0

I'm trying to run the VBS file in elevated mode through VB Scripting itself using the following code:

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

Please advise as to what is the correct way to code this.

Hackoo
  • 18,337
  • 3
  • 40
  • 70

1 Answers1

0

You can give a try like this example :

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
'**************************************
Hackoo
  • 18,337
  • 3
  • 40
  • 70