/build/static/layout/Breadcrumb_cap_w.png

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]

0 Comments   [ + ] Show comments

Answers (25)

Posted by: Inabus 15 years ago
Second Degree Green Belt
0
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
Posted by: suchi.jigar 15 years ago
Purple Belt
0
Will it matter?
because in stead of i, u r using intval...other nothing is changes
Posted by: Inabus 15 years ago
Second Degree Green Belt
0
intval = 0

Your setting it to 0 here, in the function, thus the loop will exit.

P
Posted by: suchi.jigar 15 years ago
Purple Belt
0
i tried that, it is not working
Posted by: anonymous_9363 15 years ago
Red Belt
0
- 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.
Posted by: suchi.jigar 15 years ago
Purple Belt
0
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?
Posted by: Inabus 15 years ago
Second Degree Green Belt
0
Just try:

Do While i <> 0
DisplayEnddialog

loop

change it back to "i" btw
Posted by: suchi.jigar 15 years ago
Purple Belt
0
nope...i tried that, it does not work:
Posted by: anonymous_9363 15 years ago
Red Belt
0
any suggestion? Yeh. Use IE. The only way to dismiss a pop-up is for the user to click a button, unless you want even more of a dog's breakfast and decide to use AutoIT to press the button for you.
Posted by: pjgeutjens 15 years ago
Red Belt
0
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
Senior Purple Belt
0
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.


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
Red Belt
0
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
Purple Belt
0
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
Posted by: anonymous_9363 15 years ago
Red Belt
0
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
Posted by: suchi.jigar 15 years ago
Purple Belt
0
nope...nothing is working.
Posted by: abking99 15 years ago
Second Degree Blue Belt
0
I think ur logic is,
1) u want to install any application/msi silently,
2) as well as you want to generate exit code for success and failure and
3) continuous poping message, which says-abcd Application is installing, am i right?
Posted by: suchi.jigar 15 years ago
Purple Belt
0
Yes. I give up.
Posted by: pjgeutjens 15 years ago
Red Belt
0
you might want to look into using Internet Explorer instances to do your messaging for you. Google it ;-)
Posted by: anonymous_9363 15 years ago
Red Belt
0
you might want to look into using Internet Explorer instances to do your messaging for you. See post #10, my friend.
Posted by: elgwhoppo 15 years ago
Senior Purple Belt
0
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
Senior Purple Belt
0
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
Purple Belt
0
Thanks for your efforts.....I will try to put exit codes in this script, and I will try again
Posted by: anonymous_9363 15 years ago
Red Belt
0
You're going to persist in using pop-ups as a progress indicator? I give up.
Posted by: elgwhoppo 15 years ago
Senior Purple Belt
0
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..
Posted by: suchi.jigar 15 years ago
Purple Belt
0
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 !!!
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ