我已经创建了一个批处理文件,用于使用sc.exe启动服务。但它在运行时要求管理员权限。是否有任何代码可以在批处理文件中用于将cmd提升到管理级别?
答案 0 :(得分:0)
按Windows Key + X
,然后点击Command Prompt (Admin)
。如果用户控制中心要求许可,请单击是
答案 1 :(得分:0)
你可以这样做:
@echo off
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
if %errorlevel% NEQ 0 (GOTO askAdmin)
GOTO gotAdmin
:askAdmin
::batch is being ran as normal user
echo I'm not an admin yet
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
if '%errorlevel%' NEQ '0' (
echo Requesting administrative privileges...
goto UACPrompt
) else ( goto gotAdmin )
:UACPrompt
echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
echo UAC.ShellExecute "%~s0", "", "", "runas", 1 >> "%temp%\getadmin.vbs"
"%temp%\getadmin.vbs"
exit /B
:gotAdmin
if exist "%temp%\getadmin.vbs" ( del "%temp%\getadmin.vbs" )
pushd "%CD%"
CD /D "%~dp0"
::batch is being ran as admin
echo Now I'm an admin!
pause