无忧启动论坛
标题:
批处理获取管理员权限各种写法
[打印本页]
作者:
lintrainwy
时间:
2017-11-19 21:35
标题:
批处理获取管理员权限各种写法
本帖最后由 comzhongwy 于 2017-12-28 11:25 编辑
你觉得哪种写法更好?
@ECHO OFF
setlocal ENABLEDELAYEDEXPANSION
mode con: cols=65 lines=25
color 0a
:-------------------------------------
echo 检查管理员权限
>NUL 2>&1 REG.exe query "HKU\S-1-5-19" || (
ECHO SET UAC = CreateObject^("Shell.Application"^) > "%TEMP%\Getadmin.vbs"
ECHO UAC.ShellExecute "%~f0", "%1", "", "runas", 1 >> "%TEMP%\Getadmin.vbs"
CSCRIPT //Nologo "%TEMP%\Getadmin.vbs"& DEL /f /q "%TEMP%\Getadmin.vbs" 2>NUL& Exit)
pushd "%CD%"&& CD /D "%~dp0"
:-------------------------------------
echo 检查 管理员权限...
>NUL 2>&1 REG.exe query "HKU\S-1-5-19" || (
echo CreateObject^("Shell.Application"^).ShellExecute "%~f0", "%1", "", "runas", 1 > "%TEMP%\AdminRun.vbs"
echo CreateObject^("Scripting.filesystemobject"^).DeleteFile ^(WScript.ScriptFullName^) >> "%TEMP%\AdminRun.vbs"
CSCRIPT //Nologo "%TEMP%\Getadmin.vbs"& DEL /f /q "%TEMP%\Getadmin.vbs" 2>NUL& Exit)
pushd "%CD%"&& CD /D "%~dp0"
:--------------------------------------
echo 检查管理员权限
>nul 2>&1 %Windir%\System32\FLTMC.exe || (
ECHO SET UAC = CreateObject^("Shell.Application"^) > "%TEMP%\Getadmin.vbs"
ECHO UAC.ShellExecute "%~f0", "%1", "", "runas", 1 >> "%TEMP%\Getadmin.vbs"
CSCRIPT //Nologo "%TEMP%\Getadmin.vbs"& DEL /f /q "%TEMP%\Getadmin.vbs" 2>NUL& Exit)
pushd "%CD%"&& CD /D "%~dp0"
:-------------------------------------
echo 检查 管理员权限...
>nul 2>&1 dir "%WinDir%\system32\config" || (
set vbs=Set UAC ^= CreateObject(""Shell.Application""):^
UAC.ShellExecute ""%~0"", """", """", ""runas"", 1:window.close
mshta VBScript:Execute("%vbs%")&& exit)
pushd "%CD%"&& CD /D "%~dp0"
:-------------------------------------
echo 检查 管理员权限...
>nul 2>&1 dir "%WinDir%\system32\config" || (
mshta VBScript:CreateObject("Shell.Application").ShellExecute("%~s0","goto :gotAdmin","","runas",1)(window.close)&& exit)
pushd "%CD%"&& CD /D "%~dp0"
:-------------------------------------
echo 检查 管理员权限...
%1 mshta vbscript:createobject("shell.application").shellexecute("""%~0""","::",,"runas",1)(window.close)&& exit
pushd "%CD%"&& CD /D "%~dp0"
:-------------------------------------
echo 检查 管理员权限...
%1 mshta vbscript:CreateObject("Shell.Application").ShellExecute("cmd.exe","/c %~s0 ::","","runas",1)(window.close)&& exit
pushd "%CD%"&& CD /D "%~dp0"
:-------------------------------------
::以下为你的批处理内容
pause
复制代码
作者:
dytechnology
时间:
2017-11-20 10:05
不明觉厉
作者:
wuhuayu
时间:
2017-11-21 21:23
楼主会vbs吗
作者:
lintrainwy
时间:
2017-12-28 05:09
你觉得哪种写法更好?
欢迎光临 无忧启动论坛 (http://wuyou.net./)
Powered by Discuz! X3.3