0

我正在尝试编写脚本来卸载某些应用程序。我有脚本工作,但每个程序在运行时都会抛出一个提示。

我知道应用程序支持“/S”参数,因此可以进行静默卸载。我可以从命令提示符运行卸载 /s 命令,它工作正常。没有提示,它只是卸载。

我的问题是在脚本中调用 /S 参数。无论我如何尝试,我都会不断收到语法错误。我知道这只是我和我对引号和括号的不理解,但我有点厌倦了试图让它发挥作用。所有路径中都有空格的事实使问题更加复杂,这需要更多的那些无用的引号。希望有人能告诉我我做错了什么。

另外,我真的不知道我在用 VBS 做什么,所以如果你们都可以忽略脚本的丑陋,我将不胜感激。:-)

我还有一个关于“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
4

1 回答 1

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
于 2014-05-09T20:04:38.773 回答