This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
######################################################## | |
#Check if running as administrator, if not then enables# | |
######################################################## | |
If (-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) | |
{ | |
$arguments = "& '" + $myinvocation.mycommand.definition + "'" | |
Start-Process powershell -Verb runAs -ArgumentList $arguments | |
Break |