本帖最后由 /zhqsystem/zhq 于 2024-11-27 16:51 编辑
转载请注明批处理之家
说明:
0=只运行普通权限
1=只运行管理员权限
其他值或不填=同时运行
系统要求NT6+,开启UAC有效,关闭UAC不需要这个
| call:UserAccountControlPermissionsApply 参数控制 | | goto:主标签或调用 | | goto:eof | | :UserAccountControlPermissionsApply | | rem:用户账户控制申请运行 | | cd/d "%~dp0" | | if /i "%~1"=="0" echo,非管理员权限运行,包含管理员权限自动退出 字体:淡绿色&Color 0A | | if /i "%~1"=="1" echo,保留管理员权限批处理运行,包含非管理员权限自动退出 字体:淡浅绿色&Color 0B | | if /i not "%~1"=="0" if /i not "%~1"=="1" echo,保留管理员权限和非管理员权限同时运行.如果直接管理员运行无法调用普通权限自行创建计划任务 字体:黄色&&Color 0E | | if /i "%~1"=="0" Reg.exe Query "HKU\S-1-5-20" >nul 2>nul&&exit | | if /i not "%~1"=="0" if /i not "%~1"=="1" Reg.exe Query "HKU\S-1-5-20" >nul 2>nul&&goto:eof | | if /i "%~1"=="1" Reg.exe Query "HKU\S-1-5-20" >nul 2>nul||"%systemroot%\system32\mshta.exe" vbscript:createobject("shell.application").shellexecute("""%cd%\%~nx0""",":UserAccountControlRequest",,"runas",1)(window.close)&&exit | | if /i not "%~1"=="0" if /i not "%~1"=="1" Reg.exe Query "HKU\S-1-5-20" >nul 2>nul||"%systemroot%\system32\mshta.exe" vbscript:createobject("shell.application").shellexecute("""%cd%\%~nx0""",":UserAccountControlRequest",,"runas",1)(window.close)&&goto:eof | | goto:eofCOPY |
追加带有括号路径及其括号名称批处理代码管理员权限调用方法:2019/03/30 Update
| @Echo Off&Color 0e | | SetLocal EnableDelayedExpansion | | Reg.exe Query "HKU\S-1-5-20" >nul 2>nul||( | | >"%Temp%\TEMP.Bat" ( | | Echo,@Echo Off^&Color 0e | | Echo,Reg.exe Query "HKU\S-1-5-20" ^>nul 2^>nul^|^|"%systemroot%\system32\mshta.exe" vbscript:createobject^("shell.application"^).shellexecute^("""%Temp%\Temp.Bat""","1",,"runas",1^)^(window.close^)^&^&exit | | Echo,Call "%~f0" | | ) | | ) | | Reg.exe Query "HKU\S-1-5-20" >nul 2>nul||start "" "%Temp%\TEMP.Bat" | | Reg.exe Query "HKU\S-1-5-20" >nul 2>nul||exit | | Reg.exe Query "HKU\S-1-5-20" >nul 2>nul&&echo,管理员主命令 | | pause | | 结尾处需要删除临时Bat | | goto:eofCOPY |
20241127Update
更新说明:更新虚拟磁盘和无临时文件方式调用[可以同时存在][仅仅是优化,有些数据均来自各大论坛]
| @Echo Off&Color 0e&SetLocal EnableDelayedExpansion&cd/d "%~dp0" | | set "[title][Name]=这里是批处理的名字自行更改,注:不包含扩展名 | | for /f "delims=" %%i in ('"%SystemRoot%\System32\Subst.exe"')do for /f "tokens=1,* delims=\" %%d in ("%%i")do for /f "tokens=1,* delims==<> " %%e in ("%%e")do if /i "%~d0"=="%%d" cd/d "%%~ff%~p0" | | if /i "%cd%\"=="%~dp0" (echo,非虚拟磁盘:%cd%)else (echo,虚拟磁盘已切换至:%cd%) | | >nul Reg.exe Query "HKU\S-1-5-20"||"%systemroot%\System32\Mshta.exe" VbsCript:Createobject("Shell.Application").ShellExeCute("""%~f0""","%[Title][Name]%",,"Runas",1)(Window.Close)&&Exit | | if /i not "%~f0"=="%~dp0%[title][Name]%%~x0" ren "%~f0" "%[title][Name]%%~x0" | | Reg.exe Query "HKU\S-1-5-20" >nul 2>nul&&echo,True&&title %[title][Name]% 这里换行call:这里调用后边的任何标签 这里换行论坛有问题不显示换行 goto:eofCOPY |
|