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