win7管理员权限运行bat批处理

  https://sites.google.com/site/eneerge/home/BatchGotAdmin
在bat文件前面加这段。

================================
  @echo off

:: BatchGotAdmin
:-------------------------------------
REM  --> Check for permissions
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"

REM --> If error flag set, we do not have admin.
if '%errorlevel%' NEQ '0' (
    echo Requesting administrative privileges...
    goto UACPrompt
) else ( goto gotAdmin )

:UACPrompt
    echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
    echo UAC.ShellExecute "%~s0", "", "", "runas", 1 >> "%temp%\getadmin.vbs"

    "%temp%\getadmin.vbs"
    exit /B

:gotAdmin
    if exist "%temp%\getadmin.vbs" ( del "%temp%\getadmin.vbs" )
    pushd "%CD%"
    CD /D "%~dp0"
:--------------------------------------


=================================

Comments

Popular posts from this blog

Nvidia Shield TV 2017 国行直接刷美版8.01固件

openwrt路由器忘记IP或端口等无法登录的解决方法

Thinkpad x13 Linux mint 无法正常休眠 (linux mint sleep problem)