|
本帖最后由 cclgoo 于 2022-2-26 02:05 编辑
- ::::::::::::::::::::::::::::::::::::::::::::
- :: Automatically check & get admin rights V2
- ::::::::::::::::::::::::::::::::::::::::::::
- @echo off
- CLS
- ECHO.
- ECHO =============================
- ECHO Running Admin shell(管理员权限运行)
- ECHO =============================
- :init
- setlocal DisableDelayedExpansion
- set "batchPath=%~0"
- for %%k in (%0) do set batchName=%%~nk
- set "vbsGetPrivileges=%temp%OEgetPriv_%batchName%.vbs"
- setlocal EnableDelayedExpansion
- :checkPrivileges
- NET FILE 1>NUL 2>NUL
- if '%errorlevel%' == '0' ( goto gotPrivileges ) else ( goto getPrivileges )
- :getPrivileges
- if '%1'=='ELEV' (echo ELEV & shift /1 & goto gotPrivileges)
- ECHO.
- ECHO **************************************
- ECHO Invoking UAC for Privilege Escalation
- ECHO **************************************
- ECHO Set UAC = CreateObject^("Shell.Application"^) > "%vbsGetPrivileges%"
- ECHO args = "ELEV " >> "%vbsGetPrivileges%"
- ECHO For Each strArg in WScript.Arguments >> "%vbsGetPrivileges%"
- ECHO args = args ^& strArg ^& " " >> "%vbsGetPrivileges%"
- ECHO Next >> "%vbsGetPrivileges%"
- ECHO UAC.ShellExecute "!batchPath!", args, "", "runas", 1 >>
- "%vbsGetPrivileges%"
- "%SystemRoot%System32WScript.exe" "%vbsGetPrivileges%" %*
- exit /B
- :gotPrivileges
- setlocal & pushd .
- cd /d %~dp0
- if '%1'=='ELEV' (del "%vbsGetPrivileges%" 1>nul 2>nul & shift /1)
- ::::::::::::::::::::::::::::
- ::START
- ::::::::::::::::::::::::::::
- REM Run shell as admin (example) - put here code as you like
- ECHO %batchName% Arguments: %1 %2 %3 %4 %5 %6 %7 %8 %9
- cmd /k
- ::cmd /c start dir:会打开一个新窗口后执行dir指令,原窗口会关闭;
- ::cmd /k start dir:会打开一个新窗口后执行dir指令,原窗口不会关闭。
复制代码
以管理员权限运行并切换至文件所在目录(当前目录)运行命令
|
-
-
管理员权限.txt
1.66 KB, 下载次数: 170, 下载积分: 无忧币 -2
附件为以上代码
评分
-
查看全部评分
|