Skip to content

Instantly share code, notes, and snippets.

@Simzy
Simzy / RunAsAdminNoUAC.vbs
Created January 8, 2023 11:18 — forked from codeartery/RunAsAdminNoUAC.vbs
Will run the current VBScript as an administrator without a UAC prompt after the initial setup run.
REM:<RunAsAdminNoUAC>
' Place this code at the top of your VBScript file you'd like to run with admin permissions.
' When you first run it it will ask for UAC permissions and run and add a task to your Windows 'Task Scheduler' with the name of the script.
' From here on out the VBScript file name and location should not be changed.
' Next time you run it, it will be called from the Task Scheduler with admin permissions and thus not prompt for UAC anymore.
' This script runs with WScript.exe, and does not support command line arguments.
' To delete the task, use the Windows Task Scheduler.
With CreateObject("WScript.Shell")
If WScript.Arguments.Named.Exists("CreateTask") Then
.Run "schtasks /Create /SC ONCE /TN """ & WScript.ScriptName & """ /TR ""wscript.exe \""" & WScript.ScriptFullName & "\"" /AsAdmin"" /ST 00:01 /IT /F /RL HIGHEST", 0, True