自動以管理員身份運行批處理

@echo off
rem MODE con: COLS=100 LINES=30>nul
ver | find " 5." > NUL &&goto :cmdbegin
for /f "tokens=3,*" %%I in ('reg query "HKLM\SYSTEM\CurrentControlSet\Control" /v SystemStartOptions') do set "MININT=%%I"
echo %MININT%|find /i "MININT" 1>nul 2>nul&&goto :cmdbegin
rem EnableLUA不能設置爲0,否則標準用戶無法彈出管理員賬號密碼,就無法用管理員身份運行程序。
rem reg add "HKLM\Software\Microsoft\Windows\CurrentVersion\Policies\System" /f /v EnableLUA /t REG_DWORD /d 1
if not defined username set "username=system"
net localgroup "users"|find /i "%username%" 1>nul 2>nul&&set "user=standard"
net localgroup "administrators"|find /i "%username%" 1>nul 2>nul&&set "user=administrator"
for /f "tokens=3,*" %%I in ('reg query "HKLM\Software\Microsoft\Windows\CurrentVersion\Policies\System" /v EnableLUA') do set "EnableLUA=%%I"
if "%user%"=="standard" if "%EnableLUA%"=="0x0" goto :cmdbegin
md "%SystemRoot%\system32\tempXXX" 2>nul
if exist "%SystemRoot%\system32\tempXXX" (rd /s /q "%SystemRoot%\system32\tempXXX") else (
if exist "%temp%\getadmin.vbs" del /f /q "%temp%\getadmin.vbs"
echo set uac = CreateObject^("Shell.Application"^)>"%temp%\getadmin.vbs"
echo uac.ShellExecute "%~s0","","","runas",1 >>"%temp%\getadmin.vbs"
echo WScript.Quit >>"%temp%\getadmin.vbs"
rem ping 127.0.0.1 -n 5 >nul
"%temp%\getadmin.vbs"
del "%temp%\getadmin.vbs" 1>nul 2>nul
exit /b)
:cmdbegin
rem ===================以上代碼可讓該批處理自動以管理員身份運行===========================
rem pause
@echo off
rem 判斷64位系統和32位系統
for /f "tokens=3,*" %%I in ('reg query "HKEY_LOCAL_MACHINE\HARDWARE\DESCRIPTION\System\CentralProcessor\0" /v Identifier^|find /i "Identifier"') do if not defined PROCESSOR_IDENTIFIER set "PROCESSOR_IDENTIFIER=%%I"
echo %PROCESSOR_IDENTIFIER%
if /i %PROCESSOR_IDENTIFIER:~0,3%==x86 (
echo 32位操作系統
) else (
echo 64位操作系統
)
pause
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章