我正在尝试编写一个脚本来卸载某些应用程序。我的脚本可以工作,但是每个程序在运行时都会弹出提示。
我知道应用程序支持“/S”参数,因此可以进行静默卸载。我可以从命令提示符运行 uninstall /s 命令,它工作正常。没有提示,它只是卸载。
我的问题是在脚本中调用 /S 参数。无论我如何尝试,我总是遇到语法错误。我知道这只是我和我对引号和括号的不理解,但我有点厌倦了试图让它发挥作用。所有路径中都有空格,这使得问题变得更加复杂,这需要更多的引号。 希望有人能告诉我我做错了什么。
另外,我真的不知道我在用 VBS 的东西做什么,所以如果你们都能忽略这个脚本有多么丑陋,我将不胜感激。 :-)
我还有一个关于“true”参数的问题。我的理解是,这表明当前操作应该完成,然后才能进行下一个操作。但卸载似乎是同时运行的。我对“true”参数的理解正确吗?
静默卸载的命令是:
C:\Program Files\Juniper Networks\Network Connect 7.1.9\uninstall.exe /S
这是我的脚本,没有“/S”参数。
'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
这是我的不言自明的解决方案:
' 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