vbscript for exit code not working
Please check below script, it goes continuously in loop, even after installation is done...previously it was working fine but i modified it for getting exitcode....
dim Execpath, WshShell, fso, oExec, Scriptname, Filepath, objshell, i
Set objShell = wscript.CreateObject("WScript.Shell")
Set objfso = wscript.CreateObject("Scripting.FileSystemObject")
ScriptName = WScript.ScriptFullName
FilePath = Left(ScriptName, InstrRev(ScriptName, "\"))
Exec = Filepath & "Setup\orca.msi"
ExecPath = chr(34) & FilePath & "Setup\orca.msi" & chr(34) & " /qb "
If objfso.fileexists (Exec) then
set i = objshell.run (ExecPath,1,true)
Do While (i = 0) or (i = 3010)
DisplayEnddialog
loop
MsgBox "Install successfull with error code: " & i
WScript.Quit(i)
Else
MsgBox "Install failed with error code: " & i
WScript.Quit(i)
End if
Function DisplayEndDialog()
Set objShell = wscript.CreateObject("WScript.Shell")
Const wshYesNoDialog = 0
Const wshQuestionMark = 64
Dim intval
intval = 0
intval = objShell.Popup("Installing Visual Studio 2008", _
5, "Installation in progress",wshYesNoDialog + wshQuestionMark)
End function[/align]
dim Execpath, WshShell, fso, oExec, Scriptname, Filepath, objshell, i
Set objShell = wscript.CreateObject("WScript.Shell")
Set objfso = wscript.CreateObject("Scripting.FileSystemObject")
ScriptName = WScript.ScriptFullName
FilePath = Left(ScriptName, InstrRev(ScriptName, "\"))
Exec = Filepath & "Setup\orca.msi"
ExecPath = chr(34) & FilePath & "Setup\orca.msi" & chr(34) & " /qb "
If objfso.fileexists (Exec) then
set i = objshell.run (ExecPath,1,true)
Do While (i = 0) or (i = 3010)
DisplayEnddialog
loop
MsgBox "Install successfull with error code: " & i
WScript.Quit(i)
Else
MsgBox "Install failed with error code: " & i
WScript.Quit(i)
End if
Function DisplayEndDialog()
Set objShell = wscript.CreateObject("WScript.Shell")
Const wshYesNoDialog = 0
Const wshQuestionMark = 64
Dim intval
intval = 0
intval = objShell.Popup("Installing Visual Studio 2008", _
5, "Installation in progress",wshYesNoDialog + wshQuestionMark)
End function[/align]
0 Comments
[ + ] Show comments
Answers (25)
Please log in to answer
Posted by:
Inabus
15 years ago
I would suggest that "i" is hitting either 0 or 3010 and getting stuck in the loop as your not telling i to hit an accepted exit.
set i = objshell.run (ExecPath,1,true)
Do While (i = 0) or (i = 3010) should be
set intval = objshell.run (ExecPath,1,true)
Do While (intval = 0) or (intval = 3010)
Least from what I can tell.
P
set i = objshell.run (ExecPath,1,true)
Do While (i = 0) or (i = 3010) should be
set intval = objshell.run (ExecPath,1,true)
Do While (intval = 0) or (intval = 3010)
Least from what I can tell.
P
Posted by:
suchi.jigar
15 years ago
Posted by:
Inabus
15 years ago
Posted by:
anonymous_9363
15 years ago
- Look more closely at your code. Are you sure, for example, that it's efficient to create a Shell object for every value of 'i' which isn't 0 or 3010?.
Using PopUp for a "progress" screen probably isn't the best design choice I've seen. Have a look at the many examples that show how to use IE as a UI (e.g. to display a progress bar) for VBScript.
- Why bother creating a UI when the Windows Installer engine includes one? You use the '/QB' switch to display a basic UI and then show your own UI!?
- There is a 'Scripting' forum here on AppDeploy. This thread may get moved by a moderator.
Using PopUp for a "progress" screen probably isn't the best design choice I've seen. Have a look at the many examples that show how to use IE as a UI (e.g. to display a progress bar) for VBScript.
- Why bother creating a UI when the Windows Installer engine includes one? You use the '/QB' switch to display a basic UI and then show your own UI!?
- There is a 'Scripting' forum here on AppDeploy. This thread may get moved by a moderator.
Posted by:
suchi.jigar
15 years ago
These pop-up messages, i will comment at the end.....
my requirement: till my msi installs "display end dialogues box" should come and at the end it should get exited, when installation completes successfully or unsuccessfully with exit code:
in this case, even after my installation completes "display end dialogues box" does not go.
any suggestion?
my requirement: till my msi installs "display end dialogues box" should come and at the end it should get exited, when installation completes successfully or unsuccessfully with exit code:
in this case, even after my installation completes "display end dialogues box" does not go.
any suggestion?
Posted by:
Inabus
15 years ago
Posted by:
anonymous_9363
15 years ago
Posted by:
pjgeutjens
15 years ago
Do While (i = 0) or (i = 3010)
DisplayEnddialog
loop
You're never changing the value of i inside DisplayEndDialog, you're using intval there, so once you hit 0 or 3010 you'll start looping forever
Also, your shoudn't set your i variable, it's not an object, it's a return value, instead use
i = objshell.run (ExecPath,1,true)
Posted by:
elgwhoppo
15 years ago
Suchi,
This should be in the scripting forum. But while I'm here, why even bother using a popup if all you are trying to do is get the exit code from the MSI installation. Cut out the fat and there you go.
This should be in the scripting forum. But while I'm here, why even bother using a popup if all you are trying to do is get the exit code from the MSI installation. Cut out the fat and there you go.
dim Execpath, WshShell, fso, oExec, Scriptname, Filepath, objshell, i
Set objShell = wscript.CreateObject("WScript.Shell")
Set objfso = wscript.CreateObject("Scripting.FileSystemObject")
ScriptName = WScript.ScriptFullName
FilePath = Left(ScriptName, InstrRev(ScriptName, "\"))
Exec = Filepath & "Setup\orca.msi"
ExecPath = chr(34) & FilePath & "Setup\orca.msi" & chr(34) & " /qb "
If objfso.fileexists (Exec) then
set i = objshell.run (ExecPath,1,true)
WScript.Quit(i)
End if
Posted by:
anonymous_9363
15 years ago
Jo, the pop-up is meant to be showing the user what's happening, rather than as a means to provide a return code. Actually, I'm not at all sure what it's meant to be doing, as the OP is presenting a Yes/No button with a question mark icon but not asking a question, plus that pop-up is displayed over and over again. It's a nonsense and needs completely re-writing.
Posted by:
ramesh111k
15 years ago
Check with the below change in the script in between ********************* :)
dim Execpath, WshShell, fso, oExec, Scriptname, Filepath, objshell, i
Set objShell = wscript.CreateObject("WScript.Shell")
Set objfso = wscript.CreateObject("Scripting.FileSystemObject")
ScriptName = WScript.ScriptFullName
FilePath = Left(ScriptName, InstrRev(ScriptName, "\"))
Exec = Filepath & "Setup\orca.msi"
ExecPath = chr(34) & FilePath & "Setup\orca.msi" & chr(34) & " /qb "
*************************
If objfso.fileexists (Exec) then
i = objshell.run (ExecPath,1,true)
If (i = 0) or (i = 3010) Then
DisplayEnddialog
End If
MsgBox "Install successfull with exit code: " & i
WScript.Quit(i)
Else
MsgBox "Install failed with error code: " & i
WScript.Quit(i)
End if
**********************************
Function DisplayEndDialog()
Set objShell = wscript.CreateObject("WScript.Shell")
Const wshYesNoDialog = 0
Const wshQuestionMark = 64
Dim intval
intval = 0
intval = objShell.Popup("Installing Visual Studio 2008", _
5, "Installation in progress",wshYesNoDialog + wshQuestionMark)
End function
dim Execpath, WshShell, fso, oExec, Scriptname, Filepath, objshell, i
Set objShell = wscript.CreateObject("WScript.Shell")
Set objfso = wscript.CreateObject("Scripting.FileSystemObject")
ScriptName = WScript.ScriptFullName
FilePath = Left(ScriptName, InstrRev(ScriptName, "\"))
Exec = Filepath & "Setup\orca.msi"
ExecPath = chr(34) & FilePath & "Setup\orca.msi" & chr(34) & " /qb "
*************************
If objfso.fileexists (Exec) then
i = objshell.run (ExecPath,1,true)
If (i = 0) or (i = 3010) Then
DisplayEnddialog
End If
MsgBox "Install successfull with exit code: " & i
WScript.Quit(i)
Else
MsgBox "Install failed with error code: " & i
WScript.Quit(i)
End if
**********************************
Function DisplayEndDialog()
Set objShell = wscript.CreateObject("WScript.Shell")
Const wshYesNoDialog = 0
Const wshQuestionMark = 64
Dim intval
intval = 0
intval = objShell.Popup("Installing Visual Studio 2008", _
5, "Installation in progress",wshYesNoDialog + wshQuestionMark)
End function
Posted by:
anonymous_9363
15 years ago
Wrong, I'm afraid. Your changes will cause the script to exit with an empty value for 'i', rather than a 'File not found' message (which is missing!).
Start again. Find out how to run a process, how to set a title for the process-running window and how to set a flag to keep the dialog on-screen until the process completes, rather than faff about trying to make this mess work the way the OP intended.Hint: WMI, Win32_Process, ProcessID
Start again. Find out how to run a process, how to set a title for the process-running window and how to set a flag to keep the dialog on-screen until the process completes, rather than faff about trying to make this mess work the way the OP intended.Hint: WMI, Win32_Process, ProcessID
Posted by:
abking99
15 years ago
Posted by:
pjgeutjens
15 years ago
Posted by:
anonymous_9363
15 years ago
Posted by:
elgwhoppo
15 years ago
ORIGINAL: VBScab
Jo, the pop-up is meant to be showing the user what's happening, rather than as a means to provide a return code. Actually, I'm not at all sure what it's meant to be doing, as the OP is presenting a Yes/No button with a question mark icon but not asking a question, plus that pop-up is displayed over and over again. It's a nonsense and needs completely re-writing.
I get ya. The reason I would usually use a script like the one I provided is when pushing out an upgrade script via SMS. This way I have the option of getting the exit code for the MSI installation rather than script execution, makes advertisement reporting more accurate. Not sure what all this mess about popups is about, I'm usually trying to get rid of them, not create them.
Posted by:
elgwhoppo
15 years ago
ORIGINAL: VBScab
Wrong, I'm afraid. Your changes will cause the script to exit with an empty value for 'i', rather than a 'File not found' message (which is missing!).
Start again. Find out how to run a process, how to set a title for the process-running window and how to set a flag to keep the dialog on-screen until the process completes, rather than faff about trying to make this mess work the way the OP intended.Hint: WMI, Win32_Process, ProcessID
Yep. Here is an example of a script that we used to install Visual Studio 2005 exactly how VBScab is describing. Basically the script watches for setup.exe and loops a message using Popup indicating that the install is still running. Try modifying it if it helps. Sorry for the lack of indentation, it was an early script for me.
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")
WshShell.Run "VS\Setup\setup.exe /unattendfile VS2005.ini /no_bsln_check"
Do While CHKPROC = 1
WshShell.popup "Visual Studio 2005 is Currently Installing",30,"VS2005 Install",64
Wscript.sleep delay
Loop
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
Posted by:
suchi.jigar
15 years ago
Posted by:
anonymous_9363
15 years ago
Posted by:
elgwhoppo
15 years ago
Sometimes it's warranted, for example the installation of VS2005, but that's because Microsoft recommends using their setup.exe with a response file and there is no passive option. But I totally agree that with a native MSI it's not needed.
Also as a sidebar the script I posted uses the .Name rather than .ProcessID as VBScab suggested earlier, wanted to note that if using it with the process name msiexec it will be looping for a lonnnng time..
Also as a sidebar the script I posted uses the .Name rather than .ProcessID as VBScab suggested earlier, wanted to note that if using it with the process name msiexec it will be looping for a lonnnng time..
Posted by:
suchi.jigar
15 years ago
Thanks ELGWHOPPO, you understood my scenario properly, and your sample script helped me a lot.....script in this post given by me is just a sample script, actually i had to call a setup.exe, silently, with popup messagebox, with exit codes.[Client requirement] . I did some changes in your script for getting exit codes:
If fso.fileexists (exepath1) then
i = wshshell.Run (Path2)
Do While CHKPROC = 1
WshShell.popup "Visual Studio 2005 is Currently Installing",30,"VS2005 Install",64
Wscript.sleep delay
Loop
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
end if
If (i = 0) Or (i = 3010) then
MsgBox "Office 2007 Install Successful!"
WScript.Quit(i)
Else
MsgBox "Office 2007 install failed with error code: " & i
WScript.Quit(i)
End If
Thanks to all !!!
If fso.fileexists (exepath1) then
i = wshshell.Run (Path2)
Do While CHKPROC = 1
WshShell.popup "Visual Studio 2005 is Currently Installing",30,"VS2005 Install",64
Wscript.sleep delay
Loop
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
end if
If (i = 0) Or (i = 3010) then
MsgBox "Office 2007 Install Successful!"
WScript.Quit(i)
Else
MsgBox "Office 2007 install failed with error code: " & i
WScript.Quit(i)
End If
Thanks to all !!!
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
so that the conversation will remain readable.