FloydTheDuck
asked on
VBScript will not run .exe silently
I have an SAP GUI patch (.exe) that I need to run silently on startup for all of our users. When I call it with VBS (something like the below), then it does not run silently. Even if I add the ,1,True to the end.
I've seen that when using a batch file with the /silent switch, the .exe installs silently and runs fine. However, if I call that batch file with the VBS, then it does not install (the batch file does run, however, as I've put in a line to write text to a log file when it runs).
Any ideas?
test.vbs
--------------------------
Dim Patch
Dim WshShell
Set WshShell = WScript.CreateObject("WScr ipt.Shell" )
Patch = WshShell.Run ("S:\SAP\gui710_16-1000299 5.exe /quiet /norestart")
-------------------------- --
sap-batch.bat
-------------------------- --
@echo off
IF EXIST "c:\Program Files\SAP\FrontEnd\SAPgui\ saptrace.d ll" exit
CLS
@echo Please wait for this script to run before running SAP >> c:\sap-patch-log.txt 2>>&1
gui710_16-10002995.exe /silent
@echo on
@echo You can now close this window and Run SAP
-------------------------- -
I've seen that when using a batch file with the /silent switch, the .exe installs silently and runs fine. However, if I call that batch file with the VBS, then it does not install (the batch file does run, however, as I've put in a line to write text to a log file when it runs).
Any ideas?
test.vbs
--------------------------
Dim Patch
Dim WshShell
Set WshShell = WScript.CreateObject("WScr
Patch = WshShell.Run ("S:\SAP\gui710_16-1000299
--------------------------
sap-batch.bat
--------------------------
@echo off
IF EXIST "c:\Program Files\SAP\FrontEnd\SAPgui\
CLS
@echo Please wait for this script to run before running SAP >> c:\sap-patch-log.txt 2>>&1
gui710_16-10002995.exe /silent
@echo on
@echo You can now close this window and Run SAP
--------------------------
http://www.visualbasicscript.com/tm.aspx?high=&m=82233&mpage=1#82235
If you used the /silent switch in the batch, why didnt you try it in the vbs code? Try this.
Dim Patch
Dim WshShell
Set WshShell = WScript.CreateObject("WScript.Shell")
Patch = WshShell.Run ("S:\SAP\gui710_16-10002995.exe /silent",0,True)
ASKER
Sorry, I'm backtracking now. i remember why I went to a batch file.... I had trouble getting the vbs to check if a file exists first. I'll lookup more info on EE to see how to do that.
I guess I was just overthinking. Thanks to both.
I guess I was just overthinking. Thanks to both.
checking if a file exists in VB:
http://www.activexperts.com/activmonitor/windowsmanagement/adminscripts/filesfolders/files/
http://www.activexperts.com/activmonitor/windowsmanagement/adminscripts/filesfolders/files/
Hi FloydTheDuck,
Please try the script below. It is all in vbs. It tests for the dll, then tests for the install exe, and executes the install silently.
It also logs to the c:\sap-patch-log.txt file.
Let me know how it goes.
Regards,
Daz.
Please try the script below. It is all in vbs. It tests for the dll, then tests for the install exe, and executes the install silently.
It also logs to the c:\sap-patch-log.txt file.
Let me know how it goes.
Regards,
Daz.
Dim wshShell, fso, strLogFile, ts, strCmd, strCmdLine, ret
Set wshShell = CreateObject("WScript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")
strLogFile = "c:\sap-patch-log.txt"
strCmd = "S:\SAP\gui710_16-10002995.exe"
strCmdLine = strCmd & " /silent"
Set ts = fso.OpenTextFile(strLogFile, 8, True) '# Will append to the end of the logfile
ts.WriteLine Now() & " - Executing SAP install Script"
'# Test for saptrace.dll
If fso.FileExists("c:\Program Files\SAP\FrontEnd\SAPgui\saptrace.dll") Then
ts.WriteLine Now() & " - Install aborted: c:\Program Files\SAP\FrontEnd\SAPgui\saptrace.dll found."
ts.Close
WScript.Quit(1)
End If
'# saptrace test passed, start install
ts.WriteLine Now() & " - Calling command: " & strCmdLine
If Not fso.FileExists(strCmd) Then
ts.WriteLine Now() & " - Install aborted: '" & strCmd & "' file not found."
ts.Close
WScript.Quit(1)
End If
ret = wshShell.Run(strCmdLine, 0, True)
ts.WriteLine Now() & " - Install command ended, returned: " & ret
ts.WriteLine Now() & " - End of Install Script."
ASKER
Daz, as that's a lot of code, I may want to put it in a separate script than my logon script and just call the script. What's the best way to call other vbscripts?
Hi FloydTheDuck,
You can put a line in like this:
wshShell.Run "WScript.exe ""S:\Path\To\The\Script\In stallSAP.v bs""", 1, True
... or ...
you can include it in your main script in a sub. Add the Sub to the end of your script and just call it with the
InstallSAP()
line - see below.
Regards,
Daz.
You can put a line in like this:
wshShell.Run "WScript.exe ""S:\Path\To\The\Script\In
... or ...
you can include it in your main script in a sub. Add the Sub to the end of your script and just call it with the
InstallSAP()
line - see below.
Regards,
Daz.
'# Lots of login script stuff here
InstallSAP()
'# More login script stuff here
Sub InstallSAP()
Dim wshShell, fso, strLogFile, ts, strCmd, strCmdLine, ret
Set wshShell = CreateObject("WScript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")
strLogFile = "c:\sap-patch-log.txt"
strCmd = "S:\SAP\gui710_16-10002995.exe"
strCmdLine = strCmd & " /silent"
Set ts = fso.OpenTextFile(strLogFile, 8, True) '# Will append to the end of the logfile
ts.WriteLine Now() & " - Executing SAP install Script"
'# Test for saptrace.dll
If fso.FileExists("c:\Program Files\SAP\FrontEnd\SAPgui\saptrace.dll") Then
ts.WriteLine Now() & " - Install aborted: c:\Program Files\SAP\FrontEnd\SAPgui\saptrace.dll found."
ts.Close
Exit Sub
End If
'# saptrace test passed, start install
ts.WriteLine Now() & " - Calling command: " & strCmdLine
If Not fso.FileExists(strCmd) Then
ts.WriteLine Now() & " - Install aborted: '" & strCmd & "' file not found."
ts.Close
Exit Sub
End If
ret = wshShell.Run(strCmdLine, 0, True)
ts.WriteLine Now() & " - Install command ended, returned: " & ret
ts.WriteLine Now() & " - End of Install Script."
ts.Close
End Sub
... Or if you want to call it from a .bat / .cmd batch script:
REM Batchy stuff
WScript.exe "S:\Path\To\The\Script\Ins tallSAP.vb s"
REM more batchy stuff
REM Batchy stuff
WScript.exe "S:\Path\To\The\Script\Ins
REM more batchy stuff
ASKER
Daz, in installsap.vbs, if it installs I'd like to echo to the user not to run SAP until they receive a "Finished" message. Where do I need to put the WScript.Echo? I obviously don't want it to come up if the install does not run.
ASKER
Also, both ways running the .exe thru vbs do not run silently.
Both with Daz's method:
-------------------------- -------
strCmd = "S:\SAP\gui710_16-10002995 .exe"
strCmdLine = strCmd & " /silent"
-------------------------- -------
As well as the other by Takeda
-------------------------- -
Dim Patch
Dim WshShell
Set WshShell = WScript.CreateObject("WScr ipt.Shell" )
Patch = WshShell.Run ("S:\SAP\gui710_16-1000299 5.exe /silent",0,True)
-------------------------- -
I've also tried running it this way:
-------------------------
WSHShell.Run chr(34) & "s:\SAP\gui710_16-10002995 .exe" & chr(34) & " /silent",0,true
-------------------------
But this does not work either, the user gets prompted every time "Are you sure you want to run this file?"
Both with Daz's method:
--------------------------
strCmd = "S:\SAP\gui710_16-10002995
strCmdLine = strCmd & " /silent"
--------------------------
As well as the other by Takeda
--------------------------
Dim Patch
Dim WshShell
Set WshShell = WScript.CreateObject("WScr
Patch = WshShell.Run ("S:\SAP\gui710_16-1000299
--------------------------
I've also tried running it this way:
-------------------------
WSHShell.Run chr(34) & "s:\SAP\gui710_16-10002995
-------------------------
But this does not work either, the user gets prompted every time "Are you sure you want to run this file?"
Hi
Please see the script below. There is a significant change in the way I call the installation. I am now using the Exec method to call the installation instead of the Run method. This enables me to call the installation exe, without halting the script, but still retain a link to the installation so I can tell when it finishes and return an exit code.
As you can see I can also create messages for the user using MsgBox which you can edit. You may want to add logic to check for a non-zero exit code but I do not know what exit codes the SAP installation can return.
Please note that the script will execute the installation, display a message and then pause until OK is clicked. This will not hold up the installation of SAP though.
Regards,
Daz.
Please see the script below. There is a significant change in the way I call the installation. I am now using the Exec method to call the installation instead of the Run method. This enables me to call the installation exe, without halting the script, but still retain a link to the installation so I can tell when it finishes and return an exit code.
As you can see I can also create messages for the user using MsgBox which you can edit. You may want to add logic to check for a non-zero exit code but I do not know what exit codes the SAP installation can return.
Please note that the script will execute the installation, display a message and then pause until OK is clicked. This will not hold up the installation of SAP though.
Regards,
Daz.
'# Lots of login script stuff here
InstallSAP()
'# More login script stuff here
Sub InstallSAP()
Dim wshShell, oExec, fso, strLogFile, ts, strCmd, strCmdLine
Set wshShell = CreateObject("WScript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")
strLogFile = "c:\sap-patch-log.txt"
strCmd = "c:\WINDOWS\system32\calc.exe" '"S:\SAP\gui710_16-10002995.exe"
strCmdLine = strCmd & " /silent"
Set ts = fso.OpenTextFile(strLogFile, 8, True) '# Will append to the end of the logfile
ts.WriteLine Now() & " - Executing SAP install Script"
'# Test for saptrace.dll
If fso.FileExists("c:\Program Files\SAP\FrontEnd\SAPgui\saptrace.dll") Then
ts.WriteLine Now() & " - Install aborted: c:\Program Files\SAP\FrontEnd\SAPgui\saptrace.dll found."
ts.Close
Exit Sub
End If
'# saptrace test passed, start install
ts.WriteLine Now() & " - Calling command: " & strCmdLine
If Not fso.FileExists(strCmd) Then
ts.WriteLine Now() & " - Install aborted: '" & strCmd & "' file not found."
ts.Close
Exit Sub
End If
Set oExec = wshShell.Exec (strCmdLine) '# Initiates installation but does not wait
MsgBox "SAP is now installing. Please do not attempt to Run SAP until you get an 'installation complete' Message.", vbInformation + vbSystemModal, "SAP Installation"
Do While oExec.Status = 0
'# Loop forever now until SAP installation (gui710_16-10002995.exe) is finished.
WScript.Sleep 1000 '# wait 1 second before looping to reduce CPU load.
Loop
MsgBox "SAP installation process complete.", vbInformation + vbSystemModal, "SAP Installation"
ts.WriteLine Now() & " - Install command ended, returned: " & oExec.ExitCode
ts.WriteLine Now() & " - End of Install Script."
ts.Close
End Sub
Hi,
If you are getting "Are you sure you want to run this file?", I think that this is the Windows security kicking in because the gui710_16-10002995.exe is on a network drive.
1. If you manually double the S:\SAP\gui710_16-10002995. exe file do you get the same message?
2. If you copy gui710_16-10002995.exe to the C drive and double click it, do you still get the same message?
Regards,
Daz
If you are getting "Are you sure you want to run this file?", I think that this is the Windows security kicking in because the gui710_16-10002995.exe is on a network drive.
1. If you manually double the S:\SAP\gui710_16-10002995.
2. If you copy gui710_16-10002995.exe to the C drive and double click it, do you still get the same message?
Regards,
Daz
ASKER
I rewrote the code to call a .bat file, which runs the file without getting the "Are you sure you want to run this file?" prompt.
The code is below, for the InstallSAP.vbs
I do have a problem with calling the InstallSAP.vbs from the logon.vbs, though. It works most of the time, but I just tested it with another user and it defaulted to their home directory (Q:\). So even though logon.vbs and InstallSAP.vbs are in the same directory (\\server\netlogon), it tried to call Q:\InstallSAP.vbs
Any idea why this would be? Is there anything wrong with calling the .bat file to run the script?
The code is below, for the InstallSAP.vbs
I do have a problem with calling the InstallSAP.vbs from the logon.vbs, though. It works most of the time, but I just tested it with another user and it defaulted to their home directory (Q:\). So even though logon.vbs and InstallSAP.vbs are in the same directory (\\server\netlogon), it tried to call Q:\InstallSAP.vbs
Any idea why this would be? Is there anything wrong with calling the .bat file to run the script?
Dim wshShell, objFSO, strLogFile, ts, strCmd, strCmdLine, ret
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set WshShell = WScript.CreateObject("WScript.Shell")
sBatFile = "SAP-Patch.bat"
If Not objFSO.FileExists(sBatfile) Then
MsgBox "There was a problem attempting to install your SAP Patch. Please contact the HelpDesk."
WScript.Quit
End If
If objFSO.FileExists("c:\Program Files\SAP\FrontEnd\SAPgui\saptrace.dll") Then
WScript.Quit(1)
Else
WScript.Echo "Please wait while a SAP Patch is installed. Another message will popup when finished."
wshShell.Run sBatFile, 0, True
WScript.Echo "You may now run SAP. Thank you for your patience."
End If
ASKER
Daz, in reply to your other comment. I get the prompt "Are you sure you want to run this file?" whether it is on the network or my local drive.
Hi,
I have amended my sub to call the batch file. See below.
If you want the install sap script in a different script then you need to change the way it is called.
If your logon script is .bat / .cmd then use this method:
REM =====
REM now calling InstallSAP.vbs from this same folder
~dp0InstallSAP.vbs
REM =====
If your logon script is .vbs then use this:
'# Identify current directory:
strCurrDir = Replace(WScript.ScriptFull Name, WScript.ScriptName, "")
wshShell.Run "WScript.exe """ & strCurrDir & "InstallSAP.vbs""", 0, True
I have amended my sub to call the batch file. See below.
If you want the install sap script in a different script then you need to change the way it is called.
If your logon script is .bat / .cmd then use this method:
REM =====
REM now calling InstallSAP.vbs from this same folder
~dp0InstallSAP.vbs
REM =====
If your logon script is .vbs then use this:
'# Identify current directory:
strCurrDir = Replace(WScript.ScriptFull
wshShell.Run "WScript.exe """ & strCurrDir & "InstallSAP.vbs""", 0, True
InstallSAP()
Sub InstallSAP()
Dim wshShell, oExec, fso, strCurrDir, strLogFile, ts, strCmd
Set wshShell = CreateObject("WScript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")
strCurrDir = Replace(WScript.ScriptFullName, WScript.ScriptName, "") '# Find current folder
strLogFile = "c:\sap-patch-log.txt"
strCmd = strCurrDir & "SAP-Patch.bat" '# full path to current folder and batch file.
Set ts = fso.OpenTextFile(strLogFile, 8, True) '# Will append to the end of the logfile
ts.WriteLine Now() & " - Executing SAP install Script"
'# Test for saptrace.dll
If fso.FileExists("c:\Program Files\SAP\FrontEnd\SAPgui\saptrace.dll") Then
ts.WriteLine Now() & " - Install aborted: c:\Program Files\SAP\FrontEnd\SAPgui\saptrace.dll found."
ts.Close
Exit Sub
End If
'# saptrace test passed, start install
ts.WriteLine Now() & " - Calling command: " & strCmd
If Not fso.FileExists(strCmd) Then
ts.WriteLine Now() & " - Install aborted: '" & strCmd & "' file not found."
ts.Close
Exit Sub
End If
Set oExec = wshShell.Exec (strCmd) '# Initiates installation but does not wait
MsgBox "SAP is now installing. Please do not attempt to Run SAP until you get an 'installation complete' Message.", vbInformation + vbSystemModal, "SAP Installation"
Do While oExec.Status = 0
'# Loop forever now until SAP installation (SAP-Patch.bat) is finished.
WScript.Sleep 1000 '# wait 1 second before looping to reduce CPU load.
Loop
MsgBox "SAP installation complete. You may now use SAP.", vbInformation + vbSystemModal, "SAP Installation"
ts.WriteLine Now() & " - Install command ended, returned: " & oExec.ExitCode
ts.WriteLine Now() & " - End of Install Script."
ts.Close
End Sub
[I'll be unavailable from now I'm afraid. I'll check back over the weekend, have a good one!]
ASKER
This appears to be working. I'm doing some final testing tomorrow and will let you know if I have any problems. Thanks so much!
ASKER
Daz, with your script there is a command window that opens. Where can I specify to silence this?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
That works great! Thanks Daz!
Not only did you help me solve this problem, but I learned a lot about VBS from all the different ways we attempted this. Thanks again!
Not only did you help me solve this problem, but I learned a lot about VBS from all the different ways we attempted this. Thanks again!
You're welcome, glad it worked for you.
Daz.
Daz.
ASKER
Very great help! Thanks so much!
ASKER
Daz, i know this is a closed case, but I wanted to see if you could tell me how to make the installation unattended (user doesn't have to click anything) but is NOT silent (so they can watch it work). I have too many people that completely disregard the "DO NOT USE SAP" message and they use SAP, so I want them to see the install and hopefully that will help.
Hi
Deleting or commenting out the line (line 34 above):
sgBox "SAP is about to update. Please do not attempt to Run SAP until you get an 'installation complete' Message.", vbInformation + vbSystemModal, "SAP Update"
... will stop the click OK messagebox, and if you change this ....
ret = wshShell.Run(strCmd, 0, True)
... to this (line 36 above) ...
ret = wshShell.Run(strCmd, 1, True)
... it will make the command window visible, but the patch install will still be invisible because of the /silent switch in the batch file on the gui710_16-10002995.exe command.
I'm afraid I don't know if it is possible to run the patch automated but not silent. If you run the exe manually with no /silent switch, does it require you to click Ok or anything? does it show any progress?
Daz.
Deleting or commenting out the line (line 34 above):
sgBox "SAP is about to update. Please do not attempt to Run SAP until you get an 'installation complete' Message.", vbInformation + vbSystemModal, "SAP Update"
... will stop the click OK messagebox, and if you change this ....
ret = wshShell.Run(strCmd, 0, True)
... to this (line 36 above) ...
ret = wshShell.Run(strCmd, 1, True)
... it will make the command window visible, but the patch install will still be invisible because of the /silent switch in the batch file on the gui710_16-10002995.exe command.
I'm afraid I don't know if it is possible to run the patch automated but not silent. If you run the exe manually with no /silent switch, does it require you to click Ok or anything? does it show any progress?
Daz.
ASKER
You have to click Next and "Agree" to continue with the install, then you have a progress bar after which you click "Finish."
I've done a bit of searching and I can't find a command-line switch for the SAP update that will allow it to run non-silently but automated.
Therefore the only other suggestion I can make is that you allow the black command window to show, and in the SAP-Patch.bat batch file put a line before the gui710_16-10002995.exe / silent to say something like:
@echo ... Now installing SAP update, please wait for completion before running SAP ...
I know it wont be very pretty, but otherwise you are looking at creating a GUI of your own.
Daz.
Therefore the only other suggestion I can make is that you allow the black command window to show, and in the SAP-Patch.bat batch file put a line before the gui710_16-10002995.exe / silent to say something like:
@echo ... Now installing SAP update, please wait for completion before running SAP ...
I know it wont be very pretty, but otherwise you are looking at creating a GUI of your own.
Daz.
ASKER
That's alright. Thanks Daz!