【问题标题】:Trying to script a silent uninstall with VBScript尝试使用 VBScript 编写静默卸载脚本
【发布时间】:2014-06-27 10:53:40
【问题描述】:

我正在尝试编写脚本来卸载某些应用程序。我的脚本可以运行,但是每个程序在运行时都会出现提示。

我知道应用程序支持“/S”参数,因此可以进行静默卸载。我可以从命令提示符运行卸载 /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

【问题讨论】:

    标签: vbscript uninstallstring


    【解决方案1】:

    这是我不言自明的解决方案:

    ' 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
    

    【讨论】:

    • 哇!太感谢了。我讨厌放弃一个问题,自从我发布了这个我确实让卸载开关工作(这是一个引用放置的东西,就像我怀疑的那样),但这段代码将有助于确保卸载不会在每个其他。谢谢你。我会玩弄它,看看我是否可以让它适合我的情况。再次感谢,-约翰
    • @user3583386 您也可以使用 PSEXEC 将此卸载推送到其他计算机
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-30
    • 2017-09-10
    • 2011-09-11
    • 2020-11-26
    • 1970-01-01
    相关资源
    最近更新 更多