0x0049 icon

UAC

0x0049 | PRO | 05/12/15 02:43:26 PM UTC | 0 ⭐ | 342 👁️ | Never ⏰ | []
Batch |

730 B

|

None

|

0 👍

/

0 👎

@echo off
title UAC example for batch files
 
REM Check for permissions
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
 
REM If the error flag set, we do not have admin permissions.
if '%errorlevel%' NEQ '0' (
    echo Requesting administrative privileges...
    goto UACPrompt
) else (goto GotAdmin)
 
REM Ask for admin permissions.
: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
 
REM Execute once admin permissions are granted.
:GotAdmin
    REM DO STUFF HERE

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎