beardmann

Start Service Remote Nice

Apr 21st, 2015
770
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. @echo off
  2.  
  3. IF [%1]==[] GOTO usage
  4. IF [%2]==[] GOTO usage
  5.  
  6. ping -n 1 %1 | FIND "TTL=" >NUL
  7. IF errorlevel 1 GOTO SystemOffline
  8. SC \\%1 query %2 | FIND "STATE" >NUL
  9. IF errorlevel 1 GOTO SystemOffline
  10.  
  11. :ResolveInitialState
  12. SC \\%1 query %2 | FIND "STATE" | FIND "STOPPED" >NUL
  13. IF errorlevel 0 IF NOT errorlevel 1 GOTO StartService
  14. SC \\%1 query %2 | FIND "STATE" | FIND "RUNNING" >NUL
  15. IF errorlevel 0 IF NOT errorlevel 1 GOTO StartedService
  16. SC \\%1 query %2 | FIND "STATE" | FIND "PAUSED" >NUL
  17. IF errorlevel 0 IF NOT errorlevel 1 GOTO SystemOffline
  18. echo Service State is changing, waiting for service to resolve its state before making changes
  19. sc \\%1 query %2 | Find "STATE"
  20. timeout /t 2 /nobreak >NUL
  21. GOTO ResolveInitialState
  22.  
  23. :StartService
  24. echo Starting %2 on \\%1
  25. sc \\%1 start %2 >NUL
  26.  
  27. GOTO StartingService
  28. :StartingServiceDelay
  29. echo Waiting for %2 to start
  30. timeout /t 2 /nobreak >NUL
  31. :StartingService
  32. SC \\%1 query %2 | FIND "STATE" | FIND "RUNNING" >NUL
  33. IF errorlevel 1 GOTO StartingServiceDelay
  34.  
  35. :StartedService
  36. echo %2 on \\%1 is started
  37. GOTO:eof
Advertisement