在此直观的基本脚本中需要帮助:以静默方式启动程序 [英] Need help in this visual basic script: launching a program in silent mode

查看:324
本文介绍了在此直观的基本脚本中需要帮助:以静默方式启动程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试以静默方式启动程序,以安装特定的应用程序. 以静默方式启动安装的命令行如下:

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"

我尝试使用以下方法: strCmd="C:\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.

推荐答案

如果要使用其他凭据运行命令,则可以使用RunAs命令.但是,将您的命令嵌入到RunAs命令中时,事情可能会变得棘手.这些步骤可能会帮助:

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. 确定正确的命令行语法.直接在命令提示符下进行测试,以确保它是正确的.

  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"

  • 将您的命令嵌入到RunAs命令中.您的整个命令都需要用引号引起来.另外,命令中的所有引号都需要使用\进行转义.再次,直接在命令提示符下进行测试以确保它是正确的.

  • 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\""
    

  • 将整个命令字符串转换为VBScript.无论您在何处看到报价,都可以将其加倍或将其替换为Chr(34).这是引号加倍时的外观:

  • 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\""""
    

  • 将其分配给VBScript变量.我们只需要在整个命令周围加上其他引号即可:

  • 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\"""""
    

  • 现在您可以开始了.您可以直接使用Shell.Run运行此程序:

  • Now you're ready to go. You can run this directly with Shell.Run:

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

  • 请注意,当RunAs提示您输入密码时,您仍然需要使用SendKeys,因为它无法在命令行上通过它.

    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.

    另一种方法是使用SCHTASKS安排一次性任务立即运行.使用SCHTASKS,您可以 在命令行上传递完整的凭据.

    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.

    这篇关于在此直观的基本脚本中需要帮助:以静默方式启动程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆