简体   繁体   中英

Trying to script a silent uninstall with VBScript

I am attempting to write a script to an uninstall of some applications. I have the script working, but every program throws up a prompt when run.

I know that the applications support the “/S” parameter so a silent uninstall can be done. I can run the uninstall /s command from a command prompt and it works fine. No prompts, it just uninstalls.

My problem is invoking the /S parameter in a script. No matter how I try, I keep getting syntax errors. I know this is just me and my non-understanding of quotes and parenthesis, but I'm sort of tired of trying to get it to work. The problem is compounded by the fact that all the paths have spaces in them, which necessitates more of those dang quotes. Hopefully someone can show me what I am doing wrong.

Also, I really don't know what I'm doing with VBS stuff, so I'd appreciate it if you could all overlook how ugly the script is. :-)

I also have a question about the “true” parameter. My understanding is that this indicates that the current operation should be completed before moving on to the next operation. But the uninstalls seem to run all at the same time. Am I understanding the “true” parameter correctly?

The command for a silent uninstall is:

C:\Program Files\Juniper Networks\Network Connect 7.1.9\uninstall.exe /S

Here is my script without the "/S' parameter.

'Uninstall Juniper Networks Network Connect 7.1.9

Wscript.Echo "Uninstalling 'Juniper Networks Network Connect 7.1.9'"

Dim objShell
Set objShell = WScript.CreateObject( "WScript.Shell" )
objShell.Run ("""C:\Program Files\Juniper Networks\Network Connect 7.1.9\uninstall.exe"""), 1, True
Set objShell = nothing

Here's my self-explainig solution:

' VB Script Document
'http://stackoverflow.com/questions/23569022/trying-to-script-a-silent-uninstall-with-vbscript
option explicit
Dim strResult
strResult = Wscript.ScriptName _
    & vbTab & "Uninstalling 'Juniper Networks Network Connect 7.1.9'"
Dim strCommand, intWindowStyle, bWaitOnReturn, intRetCode
' strCommand 
'   String value indicating the command line you want to run. 
'   You must include any parameters you want to pass to the executable file.
strCommand = """C:\Program Files\Juniper Networks\Network Connect 7.1.9\uninstall.exe"" /S"
'for test only strCommand = """C:\Program Files\Mozilla Firefox\firefox.exe"" -safe-mode"

' intWindowStyle
'   Optional. Integer value indicating the appearance of the program's window. 
'   Note that not all programs make use of this information.
intWindowStyle = 1
' bWaitOnReturn
'   Optional. Boolean value indicating whether the script should wait 
'   for the program to finish executing before continuing 
'   to the next statement in your script. 
'   If set to true, script execution halts until the program finishes, 
'   and Run returns any error code returned by the program. 
'   If set to false (the default), the Run method returns 0 immediately 
'   after starting the program (not to be interpreted as an error code).
bWaitOnReturn = True
strResult = strResult & vbNewLine & strCommand _
  & vbNewLine & CStr( intWindowStyle) _
  & vbNewLine & CStr( bWaitOnReturn)
Wscript.Echo strResult
Dim objShell
Set objShell = WScript.CreateObject( "WScript.Shell" )
' intRetCode
' The Run method returns an integer
intRetCode = objShell.Run( strCommand, intWindowStyle, bWaitOnReturn)
Set objShell = nothing

Wscript.Echo strResult & vbNewLine & "result=" & CStr( intRetCode)
Wscript.Quit

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM