代码:
@echo off
echo 获取Administrator权限
cacls.exe "%SystemDrive%\System Volume Information" >nul 2>nul
if %errorlevel%==0 goto Admin
if exist "%temp%\getadmin.vbs" del /f /q "%temp%\getadmin.vbs"
echo Set RequestUAC = CreateObject^("Shell.Application"^)>"%temp%\getadmin.vbs"
echo RequestUAC.ShellExecute "%~s0","","","runas",1 >>"%temp%\getadmin.vbs"
echo WScript.Quit >>"%temp%\getadmin.vbs"
"%temp%\getadmin.vbs" /f
if exist "%temp%\getadmin.vbs" del /f /q "%temp%\getadmin.vbs"
exit
:Admin
echo 成功取得Administrator权限
echo 检测MySQL状态
for /f "skip=3 tokens=4" %%i in ('sc query MySQL') do set "zt=%%i" &goto :next
:next
if /i "%zt%"=="RUNNING" (
echo MySQL服务运行中
) else (
echo 该服务现在处理停止状态
echo 启动MySQL
net start MySQL
sc start MySQL
)
效果: