Tuesday, 12 October 2010

VBScript for SMS " Launch EXE in SMS"

Requirement : To install the Patch EXE(which was repackaged) using VBscript. It should give the status in SMS reports as required by clients and create the log file so the EXE status to be updated so if there is any error we can see the log file and fix the problem.

SOLUTION
*************************************************************************************
Below code will execute the EXE with status captured to SMS reports as well.
(EXE should be in same folder)
when we advertise the program, EXE & VBS will in Distribution Point, So VB script will launch the EXE from the same location.
*************************************************************************************
Int1 = ".EXE"
'MsgBox "Copy file location = " & Int1

If objFSO.FileExists(Int1) Then
'status will give the return code in the variable
IntRet = objShell.Exec(Int1).Status

str = " Patch EXE is available and Started Execution, sleeping..."
objTS.WriteLine str
'Till the exe is installed through SMS it will be in Sleep MODE as per requirement
WScript.Sleep 600000
*************************************************************************************
Below code will Creatae Log file if it doesn't exist.
*************************************************************************************
strFileName = objFolder & "\sms\logs\.log"

If objFSO.FileExists(strFileName) Then
'Set objTS = objFSO.OpenTextFile(strFileName,FOR_READING)
'strContents = objTS.ReadAll
Set objTS = objFSO.OpenTextFile(strFileName,FOR_APPEND)
'strContents = objTS.ReadAll
Else
objfso.CreateFolder objfolder & "\SMS"
objfso.CreateFolder objfolder & "\SMS\logs"
objfso.CreateTextFile(strFileName)
'Set objTS = objFSO.OpenTextFile(strFileName,FOR_READING)
'strContents = objTS.ReadAll
Set objTS = objFSO.OpenTextFile(strFileName,FOR_WRITING)
'strContents = objTS.ReadAll
End If
*************************************************************************************