Skip to content

Instantly share code, notes, and snippets.

@sleepless-p03t
Last active October 14, 2018 01:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sleepless-p03t/83edd5ffeded635516a5a751e7c07462 to your computer and use it in GitHub Desktop.
Save sleepless-p03t/83edd5ffeded635516a5a751e7c07462 to your computer and use it in GitHub Desktop.
@echo off
IF '%PROCESSOR_ARCHITECTURE%' EQU 'amd64' (
>nul 2>&1 "%SYSTEMROOT%\SysWOW64\icacls.exe" "%SYSTEMROOT%\SysWOW64\config"
) ELSE (
>nul 2>&1 "%SYSTEMROOT%\system32\icacls.exe" "%SYSTEMROOT%\system32\config"
)
if '%errorlevel%' NEQ '0' (
goto UACPrompt
) else (
goto gotAdmin
)
:UACPrompt
echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
set params = %*:"=""
echo UAC.ShellExecute "cmd.exe", "/c ""%~s0"" %params%", "", "runas", 1 >> "%temp%\getadmin.vbs"
"%temp%\getadmin.vbs"
del "%temp%\getadmin.vbs"
exit /B
:gotAdmin
pushd "%CD%"
CD /D "%~dp0"
schtasks.exe /query /TN "notepad" >NUL 2>&1
if %errorlevel% NEQ '0' (
schtasks.exe /delete /TN "notepad" /f
)
schtasks.exe /Create /SC ONCE /TN "notepad" /TR "notepad.exe" /RL HIGHEST /SD 01/01/1910 /ST 00:00 > nul 2>&1
$p = "";$icon = "";if ([System.IntPtr]::Size -eq 8) {$p = "$env:SystemRoot\SysWOW64\schtasks.exe";$icon = "$env:SystemRoot\SysWOW64\notepad.exe"} else {$p = "$env:SystemRoot\system32\schtasks.exe";$icon = "$env:SystemRoot\system32\notepad.exe"};$WshShell = New-Object -ComObject WScript.Shell;$Shortcut = $WshShell.CreateShortcut("$env:APPDATA\Microsoft\Windows\Start Menu\Startup\notepad.lnk");$Shortcut.TargetPath = "$p";$Shortcut.Arguments = "/Run /TN `"notepad`"";$Shortcut.Description = "Runs Notepad.exe as admin";$Shortcut.IconLocation = "$icon";$Shortcut.Save();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment