Skip to content

Instantly share code, notes, and snippets.

@miyouzi
Created February 10, 2018 03:29
Show Gist options
  • Save miyouzi/a0fce09a05f231928b4b48354799002d to your computer and use it in GitHub Desktop.
Save miyouzi/a0fce09a05f231928b4b48354799002d to your computer and use it in GitHub Desktop.
批处理自动尝试提权
REM =============================检查并尝试获取管理员权限==============================
REM 借鉴 https://sites.google.com/site/eneerge/home/BatchGotAdmin
:getadmin
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
if '%errorlevel%' NEQ '0' (
echo 【正在尝试获取管理员权限】
mshta vbscript:"<html style=background:buttonface><title>BatchGetAdmin</title><body><script language=vbscript>Set UAC = CreateObject(""Shell.Application""):UAC.ShellExecute ""%~s0"", """", """", ""runas"", 1:self.close</script></body></html>"
exit
)
goto :eof
REM ==================================================================================
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment