Even if installation is done successfully, script displays "Office 2007 install failed with error code: "
pls help:

Dim WSHShell, fso, delay
strComputer = "."
Set WshShell=CreateObject("WScript.Shell")
Set fso=CreateObject("Scripting.FileSystemObject")
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

strCurrentDir = fso.GetParentFolderName(WScript.ScriptFullName)
If Right(strCurrentDir,1) <> "\" Then strCurrentDir = strCurrentDir & "\"

strprogramfiles = wshshell.expandenvironmentstrings("%programfiles%")

exepath1 = strprogramfiles & "\Microsoft Office\OFFICE11\msaccess.exe"
exepath2 = strprogramfiles & "\Microsoft Office\OFFICE12\msaccess.exe"
Path2 = chr(34) & strcurrentdir & "Setup.exe" & chr(34) & " /adminfile " & chr(34) & strcurrentdir & "FRESH INSTALLATION OFFICE2007.MSP" & chr(34)

Set iexec = wshshell.exec(path2)

Do While CHKPROC = 1
WshShell.popup "Visual Studio 2005 is Currently Installing",30,"VS2005 Install",64
Wscript.sleep delay
Loop

if (iexec.status=0) then

MsgBox "Office 2007 Install Successful: " & iexec.status
WScript.Quit(iexec.status)
Else
MsgBox "Office 2007 install failed with error code: " & iexec.status
WScript.Quit(iexec.status)
End If

Function CHKPROC
Set colProcessList = objWMIService.ExecQuery ("Select * from Win32_Process Where Name = 'setup.exe'")
For Each objProcess in colProcessList
If objProcess.Name="setup.exe" Then
CHKPROC = 1
end if
Next
End Function
0 Comments   [ + ] Show Comments

Comments

Please log in to comment

Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.

Answers

0
Try this. I noticed you took the delay declaration out, you need that. Also make sure that your command line is working successfully outside of the script. Hope this helps...


Dim WSHShell, fso, delay
delay = 10000
strComputer = "."
Set WshShell=CreateObject("WScript.Shell")
Set fso=CreateObject("Scripting.FileSystemObject")
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

strCommand = "setup.exe /adminfile ""FRESH INSTALLATION OFFICE2007.MSP"""
intRet = WshShell.run(strCommand,0,True)

Do While CHKPROC = 1
WshShell.popup "Office 2007 Installing...",30,"Office 2007 Install",64
Wscript.sleep delay
Loop

msgbox "Install exited with exit code: "+intRet
wscript.quit(intRet)

Function CHKPROC
Set colProcessList = objWMIService.ExecQuery ("Select * from Win32_Process Where Name = 'setup.exe'")
For Each objProcess in colProcessList
If objProcess.Name="setup.exe" Then
CHKPROC = 1
end if
Next
End Function

Answered 08/05/2009 by: elgwhoppo
Senior Purple Belt

Please log in to comment
0
your script is perfect....but my problem is, client is saying he does not get exit code in sms, so i have to generate exit code.
Answered 08/05/2009 by: suchi.jigar
Purple Belt

Please log in to comment
0
If you're getting an exit code on the msgbox, then it should be working. Not sure what your SMS guy is seeing. I've used that exact syntax on many scripts and it always returns the exit code.

For example, try modifying this portion of the script:


intRet = 1603
msgbox "Install exited with exit code: "+intRet
wscript.quit(intRet)


The script should absolutely return an exit code of 1603. If it doesn't, sounds like your SMS guy must be doing something off the wall.
Answered 08/05/2009 by: elgwhoppo
Senior Purple Belt

Please log in to comment
0
if (iexec.status=0) then

I took a quick look at the VBS language ref and iexec.status doesn't give you the returncode of the process
straight copy from the reference:

The Status property returns a value from an enumerated type.

WshRunning ( = 0)
The job is still running.

WshFinished ( = 1)
The job has completed.


What you're looking for is iexec.ExitCode
Answered 08/05/2009 by: pjgeutjens
Red Belt

Please log in to comment
0
Hi, i had to do only 2-3 changes in your script:
+intRet = & intRet.........i was getting compilation error
WshShell.run(strCommand,0,True)= WshShell.run(strCommand)....if i keep 0,true i was not getting pop up.

Dim WSHShell, fso, delay
delay = 10000
strComputer = "."
Set WshShell=CreateObject("WScript.Shell")
Set fso=CreateObject("Scripting.FileSystemObject")
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

strCommand = "setup.exe /adminfile ""FRESH INSTALLATION OFFICE2007.MSP"""
intRet = WshShell.run(strCommand)

Do While CHKPROC = 1
WshShell.popup "Office 2007 Installing...",30,"Office 2007 Install",64
Wscript.sleep delay
Loop

msgbox "Install exited with exit code: " & intRet


wscript.quit(intRet)

Function CHKPROC
Set colProcessList = objWMIService.ExecQuery ("Select * from Win32_Process Where Name = 'setup.exe'")
For Each objProcess in colProcessList
If objProcess.Name="setup.exe" Then
CHKPROC = 1
end if
Next
End Function

But even if i terminate the installation in middle, it thrown an error code 0, and after successfull installation also, it throws error code 0

any idea?
Answered 08/05/2009 by: suchi.jigar
Purple Belt

Please log in to comment
0
I'm thinking the setup.exe is not returning anything other than a 0 for the exit code.

Can you test through SMS by just running "setup.exe" and then cancelling the wizard? If it give you 0, there's the problem.
Answered 08/05/2009 by: elgwhoppo
Senior Purple Belt

Please log in to comment
0
Thanks for your time :)
But if i do not put pop-up message, in my script then i get perfect exit codes. For the same installation i have created bat file as well, and it also generates exit codes.....only if we are putting popup message boxes, then we are not getting proper exit codes; and my client wants pop up message box. :(
Answered 08/05/2009 by: suchi.jigar
Purple Belt

Please log in to comment
0
Suchi,

if the waitonreturn parameter of a shell.Run method is set to False (default), the run method will return immediately after starting the program and always return a 0, you then lose the ability to interpret this value as the error code of the program you run.

If you want to run the setup asynchronously from your script so you can monitor its outcome you'll want to use the Exec method, which runs the app in a child command shell

Hope this helps
Answered 08/05/2009 by: pjgeutjens
Red Belt

Please log in to comment
0
Or, do it properly by using WMI to create an event sink, start the process and get its ID (not the name, as they're not unique), then monitor the sink until the process terminates. Sounds complicated but it's really not. There's a very good sample script knocking around (on computerperformance.co.uk, maybe?) which you can easily edit to suit.
Answered 08/05/2009 by: VBScab
Red Belt

Please log in to comment
0
Are you talking about below link?
http://www.computerperformance.co.uk/ezine/ezine130.htm
Answered 08/05/2009 by: suchi.jigar
Purple Belt

Please log in to comment
0
Do you see the acronym 'WMI' anywhere on that page? If so, yes. If not, no.

Holy cow...much more of this and I'll have to commit myself to an institution. Here, you forced me into it:'// Watch (via event subscription) a shelled process and cancel it if it is still running after intintMaxTime
'// Writes a log file to watchproc.log
'// Will optionally kill the shelled process if it does not complete in x seconds.
'// Useful for environments where machines may not be consistently available.

Option Explicit

Dim strScriptName
Dim strScriptFullName
Dim strMsg
Dim objWshShell
Dim objWMIService
Dim objEventSink
Dim colProcess
Dim objProcess
Dim lngProcessID
Dim blnProcessTerminated
Dim objFSO
Dim objLogFile
Dim intCounter
Dim strQuery
Dim strPath
Dim strName
Dim strArguments
Dim intMaxTime
Dim blnFileExists

'''''''''''''''''''''''''''''''''''
' Constants for opening files
'''''''''''''''''''''''''''''''''''
Const intOpenFileForReading = 1
Const intOpenFileForWriting = 2
Const intOpenFileForAppending = 8

strScriptName = WScript.ScriptName
strScriptFullName = WScript.ScriptFullName

'// Get input parameters
If WScript.Arguments.Count = 0 Or WScript.Arguments.Count < 3 Then
'// Script was run without arguments or too few arguments
strMsg = ""
strMsg = strMsg & "Usage:" & vbCRLF
strMsg = strMsg & "You must specify:" & vbCRLF
strMsg = strMsg & vbTAB & "the path to the script/program to be run," & vbCRLF
strMsg = strMsg & vbTAB & "the name of the script/program to be run" & vbCRLF
strMsg = strMsg & vbTAB & "and, optionally, any arguments for the script/program to be run:" & vbCRLF & vbCRLF
strMsg = strMsg & "Cscript " & strScriptFullName & " <path to script/exe to be run> <name of script/exe to be run> <script/exe arguments>" & vbCRLF
MsgBox strMsg
WScript.Quit(False)
Else
strPath = WScript.Arguments(0) '// Path to script/program
strName = WScript.Arguments(1) '// Name of script/program
intMaxTime = WScript.Arguments(2) '// Nbr of seconds to wait

If WScript.Arguments.Count > 3 Then
strArguments = WScript.Arguments(3) '// Arguments to pass to script
End If
strMsg = strPath & " " & strName & strArguments
End If

Set objWshShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FilesystemObject")
Set objLogFile = objFSO.OpenTextFile(strScriptName & ".log", intOpenFileForAppending, True)

objLogFile.Write "Passed arguments: " & strMsg & vbCRLF
objLogFile.Write vbCRLF & Now() & strScriptName & " started." & vbCRLF

'// Initialise WMI
objLogFile.Write Now() & " Binding to WMI." & vbCRLF
Set objWMIService = GetObject("WINMGMTS:{impersonationLevel=impersonate,(Security)}!\\.\ROOT\CIMV2")

'// Create the Event Notification Sink
objLogFile.Write Now() & " Creating event sink." & vbCRLF
Set objEventSink = CreateObject("WbemScripting.SWbemSink")

objLogFile.Write Now() & " Connecting to event sink." & vbCRLF
WScript.ConnectObject objEventSink,"EVENTSINK_"

blnProcessTerminated = False
blnFileExists = False
strMsg = Now()

With objFSO
If .FolderExists(strPath) Then
If .FileExists(strPath & "\" & strName) Then
blnFileExists = True
strMsg = strMsg & "Launching " & strPath & "\" & strName & " " & strArguments & vbCRLF
If Len(strArguments) > 0 Then
Call ProcessLaunch(strPath & "\" & strName & " " & strArguments, strPath)
Else
Call ProcessLaunch(strPath & "\" & strName, strPath)
End If
Else
strMsg = strMsg & "File " & strName & " not found in " & strPath & vbCRLF
End If
Else
strMsg = strMsg & "Folder " & strPath & " not found" & vbCRLF
End If

objLogFile.Write strMsg

End With

If blnFileExists Then
intCounter = 0

Do While blnProcessTerminated = False
intCounter = intCounter + 1
'objLogFile.Write "Sleeping for " & intMaxTime/1000 & " seconds." & vbCRLF
WScript.Sleep 1000
If intCounter > intMaxTime Then
Call KillProcess(lngProcessID)
End If
Loop
End If

'**************************************************************
Sub ProcessLaunch(ByVal strProcessName, ByVal strProcessPath)
Dim objProcess
Dim objStartup
Dim objConfig
dim lngReturn

Const intSW_HIDE = 0 '// Hides the window and activates another window.
Const intSW_NORMAL = 1 '// Activates and displays a window.
'// If the window is minimised or maximised, the system restores it to the original size and position.
'// An application specifies this flag when displaying the window for the first time.
Const intSW_SHOWMINIMIZED = 2 '// Activates the window, and displays it as a minimised window.
Const intSW_SHOWMAXIMIZED = 3 '// Activates the window, and displays it as a maximised window.
Const intSW_SHOWNOACTIVATE = 4 '// Displays a window in its most recent size and position.
'// This value is similar to SW_SHOWNORMAL, except that the window is not activated.
Const intSW_SHOW = 5 '// Activates the window, and displays it at the current size and position.
Const intSW_MINIMIZE = 6 '// Minimises the specified window, and activates the next top level window in the Z order.
Const intSW_SHOWMINNOACTIVE = 7 '// Displays the window as a minimised window. This value is similar to SW_SHOWMINIMZED,
'// except that the window is not activated.
Const intSW_SHOWNA = 8 '// Displays the window at the current size and position. This value is similar to SW_SHOW,
'// except that the window is not activated.
Const intSW_RESTORE = 9 '// Activates and displays the window. If the window is minimised or maximised, the system
'// restores it to the=original size and position. An application specifies this flag when
'// restoring a minimised window.
Const intSW_SHOWDEFAULT = 10 '// Sets the show state based on the SW_ value that is specified in the STARTUPINFO structure
'// passed to the CreateProcess function by the program that starts the application.
Const intSW_FORCEMINIMIZE = 11 '// Windows Server 2003, Windows 2000, and Windows XP:
'// Minimises a window, even when the thread that owns the window is hung.
'// Only use this flag when minimising windows from a different thread.

Set objStartup = objWMIService.Get("Win32_ProcessStartup")
Set objConfig = objStartup.SpawnInstance_
objConfig.ShowWindow = intSW_NORMAL

Set objProcess = objWMIService.Get("Win32_Process")

'Err.Clear
lngReturn = objProcess.Create(strProcessName, strProcessPath, objConfig, lngProcessID)

If lngReturn = 0 Then
strMsg = strProcessName & " PID:" & lngProcessID & " created." & vbCRLF
objLogFile.Write strMsg
Else
strMsg = "Failed to launch " & strProcessName & vbCRLF
strMsg = strMsg & "Error " & lngReturn & ":"
Select Case lngReturn
Case 2
strMsg = strMsg & "Access denied."
Case 3
strMsg = strMsg & "Insufficient privilege."
Case 8
strMsg = strMsg & "Unknown failure."
Case 9
strMsg = strMsg & "Path not found."
Case 21
strMsg = strMsg & "Invalid parameter."
End Select

objLogFile.Write strMsg
Exit Sub
End If

Call WatchProcess(lngProcessID)
End Sub

'**************************************************************
Sub KillProcess(ByVal lngProcessID)

strQuery = ""
strQuery = strQuery & "SELECT "
strQuery = strQuery & "* "
strQuery = strQuery & "FROM "
strQuery = strQuery & "Win32_Process "
strQuery = strQuery & "WHERE "
strQuery = strQuery & "ProcessID="
strQuery = strQuery & lngID

Set colProcess = objWMIService.ExecQuery(strQuery)

If colProcess.Count <> 0 Then
For Each objProcess In colProcess
objProcess.Terminate()
objLogFile.Write "Process " & lngProcessID & " timed out " & Now() & vbCRLF
objEventSink.Cancel()
blnProcessTerminated=True
Next
End If
End Sub

'**************************************************************
Sub WatchProcess(ByVal lngProcessID)

strQuery = ""
strQuery = strQuery & "SELECT "
strQuery = strQuery & "* "
strQuery = strQuery & "FROM "
strQuery = strQuery & "__InstanceOperationEvent "
strQuery = strQuery & "WITHIN 1 "
strQuery = strQuery & "WHERE "
strQuery = strQuery & "TargetInstance "
strQuery = strQuery & "ISA "
strQuery = strQuery & "'Win32_Process' "
strQuery = strQuery & "AND "
strQuery = strQuery & "TargetInstance.ProcessID='"
strQuery = strQuery & lngID & "'"

objWMIService.ExecNotificationQueryAsync objEventSink, strQuery
End Sub

'**************************************************************
Sub EVENTSINK_OnObjectReady(objInstance, objAsyncContext)

If objInstance.Path_.Class = "__InstanceDeletionEvent" Then
strMsg = "Process " & objInstance.TargetInstance.ProcessID & " terminated at " & Now() & vbCRLF
objLogFile.Write strMsg

objEventSink.Cancel()
blnProcessTerminated = True
WScript.Quit
End If

End Sub

Sub EVENTSINK_OnCompleted(objInstance, objAsyncContext)

strMsg = "ExecQueryAsync completed"
objLogFile.Write strMsg
blnProcessTerminated = True

End Sub
Here's an IE-based progress bar http://www.visualbasicscript.com/m_74397/mpage_1/key_/tm.htm#75305
Answered 08/05/2009 by: VBScab
Red Belt

Please log in to comment
0
Suchi,

I got similar requirement today i hope it will be helpfull who ever is having similar requirements.
To capture the return code u need to add .status ie
*********
Set iexec = wshshell.exec(path2).status
*********
For If condition

if iexec = 0 then
************

I hope it will meet your requirements[:)]
Answered 10/05/2010 by: OMUS
Senior Yellow Belt

Please log in to comment
Answer this question or Comment on this question for clarity