【问题标题】:How to run an application in elevated mode through VB Scripting? [duplicate]如何通过 VB 脚本在提升模式下运行应用程序? [复制]
【发布时间】:2019-03-15 10:46:37
【问题描述】:

我正在尝试使用以下代码通过 VB 脚本本身以提升模式运行 VBS 文件:

Set objShell = CreateObject("Shell.Application")
objShell.ShellExecute "<Path to VBS.vbs>","","", "elevate", "", "runas", 1

请告知正确的编码方式。

【问题讨论】:

    标签: vbscript


    【解决方案1】:

    你可以试试这个例子:

    Option Explicit
    'Run as Admin
    If Not WScript.Arguments.Named.Exists("elevate") Then
       CreateObject("Shell.Application").ShellExecute DblQuote(WScript.FullName) _
       , DblQuote(WScript.ScriptFullName) & " /elevate", "", "runas", 1
        WScript.Quit
    End If
    ' Main Program
    Dim ws,Command,ret,objFSO,LogFile,SysFolder 
    set ws = createobject("wscript.shell")
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    SysFolder = objFSO.GetSpecialFolder(1)
    LogFile = SysFolder & "\" & "energy-report.html"
    Command = "cmd /K Title Please wait ... & Powercfg /energy"
    msgbox Command
    ret = ws.run(command,1,True)
    If objFSO.FileExists(LogFile) Then ws.run LogFile
    '**************************************
    Function DblQuote(Str)
        DblQuote = chr(34) & Str & chr(34)
    End function
    '**************************************
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-26
      • 1970-01-01
      • 2021-01-09
      • 1970-01-01
      • 1970-01-01
      • 2012-02-21
      相关资源
      最近更新 更多