Need help in this visual basic script: launching a

2019-08-28 22:18发布

问题:

I'm trying to launch a program in silent mode, to install a certain application. The command line for launching the installation in silent mode is as follows:

setup.exe /s /v" /q"

I tried using the following: strCmd="C:\setup.exe"" /s /v"""" /q"""

But obviously this doesn't work. Can anyone help me on writing the right syntax. I know there's something wrong with the quotes as an escape character. I have wasted a lot of time trying to figure that out. Any help is highly appreciated.

回答1:

If you want to run the command using different credentials, you can use the RunAs command. Things can get tricky when embedding your command within the RunAs command, however. These steps may help:

  1. Determine the proper command line syntax. Test this directly at the command prompt to ensure it's correct.

    c:\setup.exe /s /v"/qn"
    
  2. Embed your command within the RunAs command. Your entire command needs to be surrounded with quotes. In addition, any quotes within your command need to be escaped with \. Again, test this directly at the command prompt to ensure it's correct.

    runas.exe /user:DOMAIN\USER "c:\setup.exe /s /v\"/qn\""
    
  3. Convert the entire command string to VBScript. Wherever you see a quote, double it, or replace it with Chr(34). Here is how it would look when the quotes are doubled:

    runas.exe /user:DOMAIN\USER ""c:\setup.exe /s /v\""/qn\""""
    
  4. Assign it to a VBScript variable. We just need to put additional quotes around the entire command:

    strCommand = "runas.exe /user:DOMAIN\USER ""c:\setup.exe /s /v\""/qn\"""""
    
  5. Now you're ready to go. You can run this directly with Shell.Run:

    With CreateObject("WScript.Shell")
        .Run strCommand
    End With
    

Note that you will still need to use SendKeys when RunAs prompts you for the password, as it provides no way to pass it on the command line.

An alternative method is to use SCHTASKS to schedule a one-time task to be run immediately. With SCHTASKS, you can pass the complete credentials on the command line.



回答2:

From the comments it is determined the correct install string. For VBS, you can run it (on the machine):

Dim oShell
Set oShell = WScript.CreateObject ("WScript.Shell")
oShell.run "cmd /C C:\setup.exe /s /v""/qn"""
Set oShell = Nothing

If you don't want to use GPO to deploy, you can also push the install task to computers manually with PSEXEC.EXE, it does not require the setup.exe to be on the computer and a network share folder is good for this.