How to run vbs as administrator from vbs? How to run vbs as administrator from vbs? windows windows

How to run vbs as administrator from vbs?


If UAC is enabled on the computer, something like this should work:

If Not WScript.Arguments.Named.Exists("elevate") Then  CreateObject("Shell.Application").ShellExecute WScript.FullName _    , """" & WScript.ScriptFullName & """ /elevate", "", "runas", 1  WScript.QuitEnd If'actual code


Add this to the beginning of your file:

Set WshShell = WScript.CreateObject("WScript.Shell")If WScript.Arguments.Length = 0 Then  Set ObjShell = CreateObject("Shell.Application")  ObjShell.ShellExecute "wscript.exe" _    , """" & WScript.ScriptFullName & """ RunAsAdministrator", , "runas", 1  WScript.QuitEnd if


fun lil batch file

@set E=ECHO &set S=SET &set CS=CScript //T:3 //nologo %~n0.vbs /REALTIME^>nul^& timeout 1 /NOBREAK^>nul^& del /Q %~n0.vbs&CLS@%E%off&color 4a&title %~n0&%S%CX=CLS^&EXIT&%S%BS=^>%~n0.vbs&%S%G=GOTO &%S%H=shell&AT>NULIF %ERRORLEVEL% EQU 0 (    %G%2) ELSE (    if not "%minimized%"=="" %G%1)%S%minimized=true & start /min cmd /C "%~dpnx0"&%CX%:1%E%%S%%H%=CreateObject("%H%.Application"):%H%.%H%Execute "%~dpnx0",,"%CD%", "runas", 1:%S%%H%=nothing%BS%&%CS%&%CX%:2%E%%~dpnx0 fvcLing admin mode look up&wmic process where name="cmd.exe" CALL setpriority "realtime"& timeout 3 /NOBREAK>nul:3%E%x=msgbox("end of line" ,48, "%~n0")%BS%&%CS%&%CX%