【问题标题】:How to pass arguments to a script that auto run as administrator?如何将参数传递给以管理员身份自动运行的脚本?
【发布时间】:2015-11-01 20:29:31
【问题描述】:

如何将参数传递给以管理员身份自动运行的脚本?

If WScript.Arguments.Count >= 1 Then
  Command1 = WScript.Arguments.Item(0)
End If

If WScript.Arguments.Named.Exists("elevated") = False Then
  CreateObject("Shell.Application").ShellExecute "wscript.exe", """" & _
    WScript.ScriptFullName & """ /elevated", "", "runas", 1
  WScript.Quit
End If

WScript.Echo Command1

【问题讨论】:

    标签: vbscript elevated-privileges


    【解决方案1】:

    将参数添加到您已有的参数列表中 (/elevated):

    If WScript.Arguments.Count >= 1 Then
      Command1 = WScript.Arguments.Item(0)
    End If
    
    If WScript.Arguments.Named.Exists("elevated") = False Then
      CreateObject("Shell.Application").ShellExecute "wscript.exe", """" & _
        WScript.ScriptFullName & """ " & Command1 & " /elevated", "", "runas", 1
      WScript.Quit
    End If
    
    WScript.Echo Command1

    【讨论】:

      猜你喜欢
      • 2016-10-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-08
      • 1970-01-01
      • 2022-06-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多