以管理员身份重新启动打印机服务

@echo off
echo.
echo 关闭打印机服务
echo.
echo ----------------------------------
rem 以管理员身份关闭打印机服务
runas /savecred /user:administrator "net stop spooler"
echo.
rem 等待1秒钟,再执行下一步
  setlocal enableextensions
  echo %time%
  call :ProcDelay 100
  echo %time%
  goto :start

  :ProcDelay delayMSec_
  setlocal enableextensions
  for /f "tokens=1-4 delims=:. " %%h in ("%time%") do set start_=%%h%%i%%j%%k
    :_procwaitloop
    for /f "tokens=1-4 delims=:. " %%h in ("%time%") do set now_=%%h%%i%%j%%k
    set /a diff_=%now_%-%start_%
  if %diff_% LSS %1 goto _procwaitloop
  endlocal & goto :EOF
rem 以管理员身份重新启动打印机服务
:start 
runas /savecred /user:administrator "net start spooler"

你可能感兴趣的:(服务,休闲,打印机,重新启动,打印机服务)