Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @echo off
- setlocal ENABLEDELAYEDEXPANSION
- REM Check admin privileges
- net session >nul 2>&1
- if !ErrorLevel! equ 0 (set "IS_ADMIN=true") else (set "IS_ADMIN=false")
- if "%1" == "TASKRUN" (
- if "!IS_ADMIN!" == "true" (
- REM Run script
- REM ====================
- REM Put your commands in here. They will run with admin privileges.
- REM ====================
- REM ===== EXAMPLE ======
- REM cd /d "E:\Program Files\Hotta\WmGpLaunch\"
- REM start "First" "E:\Program Files\Hotta\WmGpLaunch\WmgpLauncher.exe"
- ) else (
- mshta vbscript:Execute^("msgbox ""This task requires admin privileges"",0,""Error"":close"^)
- )
- ) else (
- set "TNAME=SkipUAC\%~n0"
- schtasks /query /tn "!TNAME!" >nul 2>&1
- if !ErrorLevel! equ 0 (
- REM Task exists. Run it.
- echo Task detected. Running it...
- schtasks /run /tn "!TNAME!"
- ) else (
- REM Task doesn't exists. Create it.
- echo Task is not detected. Creating new one...
- REM Task creation needs admin privileges
- if not "!IS_ADMIN!" == "true" (goto ELEVATE)
- schtasks /create /f /tn "!TNAME!" /sc ONCE /st "23:59" /tr "\"%~dpnx0\" TASKRUN" /rl HIGHEST
- if !ErrorLevel! equ 0 (
- REM Run newly created task
- schtasks /run /tn "!TNAME!"
- ) else (
- REM Task creation failed
- mshta vbscript:Execute^("msgbox ""Failed to create task"",0,""Failed"":close"^)
- )
- )
- )
- goto:eof
- :ELEVATE
- cd /d %~dp0
- mshta "javascript: var shell = new ActiveXObject('shell.application'); shell.ShellExecute('%~nx0', '', '', 'runas', 1);close();"
- exit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement