Monday, December 28, 2009

Jacareto

A good testing tool with macro

http://jacareto.sourceforge.net/wiki/index.php/Main_Page

Writing and Compiling in Visual Basic

To compile use the command below

c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\vbc.exe code.vb

Sample 1 (Console)
--------
Module Tester

Sub Main()
Console.Write("Welcome to ")
Console.WriteLine("Visual Basic!")
End Sub ' Main

End Module


Sample 2 (GUI)
--------
Imports System
Imports System.Windows.Forms

Class MyFirstForm
Inherits Form

Private WithEvents mybutton As Button

Public Sub New()
Me.Text = "Hello, WinForms!"
mybutton = New Button()
mybutton.Text = "Click Me!"
Me.Controls.Add(mybutton)
End Sub

Public Sub mybutton_Click(sender As Object, e As EventArgs) Handles mybutton.Click
MessageBox.Show("Message")
End Sub

End Class

Class MyFirstApp
Shared Sub Main()
Dim myform As Form = New MyFirstForm()
Application.Run(myform)
End Sub
End Class

Friday, December 18, 2009

Creating users in Solaris

useradd -u 2372 -s /bin/ksh -c "Thachudayakaimal, Ullas" -d /home/tullas -m tullas

/usr/sbin/groupadd -g 102 weblogic

Stop Service from Script

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
' Obtain an instance of the the class
' using a key property value.
Set objShare = objWMIService.Get("Win32_Service.Name='ActiveMQ'")

' no InParameters to define

' Execute the method and obtain the return status.
' The OutParameters object in objOutParams
' is created by the provider.
Set objOutParams = objWMIService.ExecMethod("Win32_Service.Name='ActiveMQ'", "StopService")

' List OutParams
Wscript.Echo "Out Parameters: "
Wscript.echo "ReturnValue: " & objOutParams.ReturnValue

Start Service with a script

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
' Obtain an instance of the the class
' using a key property value.
Set objShare = objWMIService.Get("Win32_Service.Name='ActiveMQ'")

' no InParameters to define

' Execute the method and obtain the return status.
' The OutParameters object in objOutParams
' is created by the provider.
Set objOutParams = objWMIService.ExecMethod("Win32_Service.Name='ActiveMQ'", "StartService")

' List OutParams
Wscript.Echo "Out Parameters: "
Wscript.echo "ReturnValue: " & objOutParams.ReturnValue

Creating Queues in Windows with C#

Compile below code with following line

c:\windows\microsoft.net\framework\v2.0.50727\csc /nologo /out:qMaker.exe qMaker.cs


#qMaker.cs

using System;
using System.Messaging;

namespace MyProject
{
///
/// Provides a container class for the example.
///

public class MyNewQueue
{

//**************************************************
// Provides an entry point into the application.
//
// This example creates new public and private
// queues.
//**************************************************

public static void Main()
{
// Create a new instance of the class.
MyNewQueue myNewQueue = new MyNewQueue();

// Create public and private queues.
// myNewQueue.CreatePublicQueues();
myNewQueue.CreatePrivateQueues();

return;
}


//**************************************************
// Creates public queues and sends a message.
//**************************************************

public void CreatePublicQueues()
{

// Create and connect to a public Message Queuing queue.
if (!MessageQueue.Exists(".\\newPublicQueue"))
{
// Create the queue if it does not exist.
MessageQueue myNewPublicQueue =
MessageQueue.Create(".\\newPublicQueue");

// Send a message to the queue.
myNewPublicQueue.Send("My message data.");
}

// Create (but do not connect to) a second public queue.
if (!MessageQueue.Exists(".\\newPublicResponseQueue"))
{
MessageQueue.Create(".\\newPublicResponseQueue");
}

return;

}


//**************************************************
// Creates private queues and sends a message.
//**************************************************

public void CreatePrivateQueues()
{

// Create and connect to a private Message Queuing queue.
if (!MessageQueue.Exists(".\\Private$\\newPrivQueue"))
{
// Create the queue if it does not exist.
MessageQueue myNewPrivateQueue =
MessageQueue.Create(".\\Private$\\newPrivQueue");


// Send a message to the queue.
// myNewPrivateQueue.Send("My message data.");
}

// Create (but do not connect to) a second private queue.
if (!MessageQueue.Exists(".\\Private$\\newResponseQueue"))
{
MessageQueue.Create(".\\Private$\\newResponseQueue");
}

return;
}
}
}

Search and Replace strings in file with Regex

Eg

cscript searchAndReplace.vbs "jdbc:microsoft:sqlserver://GWMPAPP01:1433;DatabaseName=ReportCaster" "jdbc:microsoft:sqlserver://GWMPXXXXAPP01:1433;DatabaseName=ReportCaster" install.cfg





Dim FileName, Find, ReplaceWith, FileContents, dFileContents, regEx, CurrentMatch, CurrentMatches

Find = WScript.Arguments(0)

ReplaceWith = WScript.Arguments(1)

FileName = WScript.Arguments(2)



Set regEx = New RegExp

regEx.Pattern = Find

regEx.IgnoreCase = True

regEx.Global = True

regEx.MultiLine = True





'Read source text file

FileContents = GetFile(FileName)



'replace all string In the source file



dFileContents=regEx.Replace(FileContents, ReplaceWith)



'Compare source And result

if dFileContents <> FileContents Then

'write result If different

WriteFile FileName, dFileContents



Wscript.Echo "Replace done."

If Len(ReplaceWith) <> Len(Find) Then 'Can we count n of replacements?

Wscript.Echo _

( (Len(dFileContents) - Len(FileContents)) / (Len(ReplaceWith)-Len(Find)) ) & _

" replacements."

End If

Else

Wscript.Echo "Searched string Not In the source file"

End If



'Read text file

function GetFile(FileName)

If FileName<>"" Then

Dim FS, FileStream

Set FS = CreateObject("Scripting.FileSystemObject")

on error resume Next

Set FileStream = FS.OpenTextFile(FileName)

GetFile = FileStream.ReadAll

End If

End Function



'Write string As a text file.

function WriteFile(FileName, Contents)

Dim OutStream, FS



on error resume Next

Set FS = CreateObject("Scripting.FileSystemObject")

Set OutStream = FS.OpenTextFile(FileName, 2, True)

OutStream.Write Contents

End Function

Creating shares and setting permissions

md m:\lvshare

net share "MyShare=m:\lvshare"

cacls m:\lvshare /e/g Everyone:C

Env variable creation is Automation

Here is the batch file

REM Usage eg. thisFileName.bat 172.18.20.219 D09
setx -m /S 172.18.20.219 MAILHOST %1
setx -m /S 172.18.20.219 ENV %2

ODBC DSN Creation script

ODBCCONF.exe CONFIGSYSDSN "SQL Server" "DSN=dsGiftTracking | Description=Gift Tracking Data Source | SERVER=sqlserver01 | Trusted_Connection=Yes | Database=dbGiftTracking"

Thursday, December 10, 2009

Search and Replace function in VBS

Call this with below parameters


Eg.
cscript searchAndReplace.vbs "GWSQL2KPE1" "GPAPP01" install.cfg


Dim FileName, Find, ReplaceWith, FileContents, dFileContents, regEx, CurrentMatch, CurrentMatches
Find = WScript.Arguments(0)
ReplaceWith = WScript.Arguments(1)
FileName = WScript.Arguments(2)

Set regEx = New RegExp
regEx.Pattern = Find
regEx.IgnoreCase = True
regEx.Global = True
regEx.MultiLine = True


'Read source text file
FileContents = GetFile(FileName)

'replace all string In the source file

dFileContents=regEx.Replace(FileContents, ReplaceWith)

'Compare source And result
if dFileContents <> FileContents Then
'write result If different
WriteFile FileName, dFileContents

Wscript.Echo "Replace done."
If Len(ReplaceWith) <> Len(Find) Then 'Can we count n of replacements?
Wscript.Echo _
( (Len(dFileContents) - Len(FileContents)) / (Len(ReplaceWith)-Len(Find)) ) & _
" replacements."
End If
Else
Wscript.Echo "Searched string Not In the source file"
End If

'Read text file
function GetFile(FileName)
If FileName<>"" Then
Dim FS, FileStream
Set FS = CreateObject("Scripting.FileSystemObject")
on error resume Next
Set FileStream = FS.OpenTextFile(FileName)
GetFile = FileStream.ReadAll
End If
End Function

'Write string As a text file.
function WriteFile(FileName, Contents)
Dim OutStream, FS

on error resume Next
Set FS = CreateObject("Scripting.FileSystemObject")
Set OutStream = FS.OpenTextFile(FileName, 2, True)
OutStream.Write Contents
End Function

Monday, December 07, 2009

Apache POI and Jython

import sys

def setClassPath():
libDir = "E:/apps/jython2.5.1/com/"
classPaths = ["poi-3.5-FINAL-20090928.jar","commons-logging-1.1.jar","log4j-1.2.13.jar","poi-scratchpad-3.5-FINAL-20090928.jar"]
for classPath in classPaths:
sys.path.append(libDir + classPath)


setClassPath()

from org.apache.poi.hssf.usermodel import *
from java.io import FileInputStream

file = "users.xls"

fis = FileInputStream(file)
wb = HSSFWorkbook(fis)
sheet = wb.getSheetAt(0)

# get No. of rows
rows = sheet.getPhysicalNumberOfRows()
# print wb, sheet, rows

cols = 0 # No. of columns
tmp = 0

# This trick ensures that we get the data properly even if it
# doesn.t start from first few rows
for i in range(0, 10,1):
row = sheet.getRow(i)
if(row != None):
tmp = sheet.getRow(i).getPhysicalNumberOfCells()
if tmp > cols:
cols = tmp
# print cols

for r in range(0, rows, 1):
row = sheet.getRow(r)
# print r
if(row != None):
for c in range(0, cols, 1):
cell = row.getCell(c)
if cell != None:
# print cell
pass


print sheet.getRow(5).getCell(3)

#wb.close()
fis.close()

Setting Java Classpath in Jython

import sys

def setClassPath():
libDir = "E:/apps/jython2.5.1/com/"
classPaths = ["poi-3.5-FINAL-20090928.jar","commons-logging-1.1.jar","log4j-1.2.13.jar","poi-scratchpad-3.5-FINAL-20090928.jar"]
for classPath in classPaths:
sys.path.append(libDir + classPath)

setClassPath()

from org.apache.poi.hssf.usermodel import *
from java.io import FileInputStream

Thursday, December 03, 2009

Adobe Reader Installer Automation

FEAD Optimizer is a system that is used to compress installation files into a highly compact distributable file. The intention is of course to save on bandwidth and make installation a lot more reliable. The FEAD compressed file works sort of like an executable ZIP file. But unlike a ZIP file there are no third party tools that allow the contents to be extracted easily to a folder, also there are no command line options posted on the Netopsystems website.
In my experience of FEAD Optimized files, they take a very long time to re-compose on the target machine. When you multily the re-compose time on lots of machines, you start to wonder how to decompress the files and save yourself precious time.
Until now, the only method that I have found effective in locating the re-composed files, is to use FileMon (from www.sysinternals.com) and monitor the location of where the files are being stored. Then copying the files to a safe location and cancelling the software installation. I can then use the MSI files to deploy the software using Active Directory or the RM CC3 Management tools.
I have even emailed Netopsystems asking if there are command line options, but they have never replied. I had given up hope of ever finding the command line switches until I came across them in an installation manual for a product that uses the FEAD system.
FEAD Command line switches -nos_ne No execution ? Extracts the files from the Setup utility but does not execute the Setup utility or delete the setup files.-nos_nd No delete ? Does not remove the setup files after executing the Setup utility. If the -nos_-ne switch is also present, the -nos_-nd switch is overridden.

-nos_d Delete ? Removes the setup files after executing the Setup utility. If the -nos_-ne switch is also present, the -nos_-d switch is overridden.

-nos_s Silent mode ? Installs the setup files in silent mode. Installs automatically when using: /s, /S, -s, -S, /q, /Q, -q, -Q.

-nos_o"" Output folder ? The folder to which you want to extract the setup files.

So running the executable with the following command line switches will extract the files from the FEAD archive to a location of your choosing and not execute the setup file.
program.exe -nos_ne -nos_o"C:\FEAD_Extracted"
It is also possible to send parameters to the setup/MSI file inside the FEAD archive, for example this command would change the default installation path of an MSI installer.
program.exe -nos_d INSTALLDIR="C:\Program Files\Install Here"
To run an automated silent install of a contained MSI file use this command

program.exe -nos_d /qb
As you can see, the FEAD file is actually a lot more flexiable than it appears to be and I am supprised that Netopsystems don't put this type of information onto their support site. After all they are selling deployment software to big companies who intern sell the software to other big companies who need to deploy software with more flexibility.
Common Applications that use the FEAD Optimizer format are;
Adobe Acrobat Reader 6
Adobe Acrobat Reader 7
McAfee VirusScan 8.0i
McAfee VirusScan 7.10
and many more...

The command line options work for both version 1 and 2 of the FEAD system
I hope that you will have found this useful and that it will save you hours of figuring out how to save yourself time and effort waiting for the optimiser to finish re-composing the files that you need.
Download the FEAD Extractor Tool so that you don't need to fuss with the command line parameters.
http://www.schooltechnician.co.uk/knowledge_base/general/fead_optimizer_extract_tool.html

Basic to C Language converter

This is a good converter.


http://bax-basic.sourceforge.net/