如何通过VB脚本以提升模式运行应用程序?

时间:2018-10-10 13:42:31

标签: vbscript

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

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

请告知正确的编码方式。

1 个答案:

答案 0 :(得分:0)

您可以尝试以下示例:

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
'**************************************