如果崩溃,我想运行批处理脚本来启动Windows服务,因此我将恢复服务配置为运行第一次失败,第二次失败和后续失败的程序
如果我单击以管理员身份运行或手动单击,但在Windows服务恢复中运行程序选项下的相同脚本不起作用(显示Access is denied
),我的脚本正常工作
该服务在没有管理员权限的网络服务帐户下运行
脚本 -
@echo on
setlocal
CD /D "C:\ServiceBatch"
set email="GUID@domain.com"
set service=LanmanWorkstation
set output=LanmanWorkstation.txt
set Subject=LanmanWorkstation
net start %service%
sc query %service% >%output%
if errorlevel 1 (
wmailto %email% -s"%service% Started Succesfully" -t%output%
)
自我提升的脚本作为管理员
:: BatchGotAdmin (Run as Admin code starts)
REM --> Check for permissions
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
REM --> If error flag set, we do not have admin.
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"
:: BatchGotAdmin (Run as Admin code ends)