Services Manipulation
Jump to navigation
Jump to search
To stop, start or check status of a Service remotely, you can use the sc utility as follows:
sc \\servername stop ServiceName sc \\servername start ServiceName sc \\servername query ServiceName
Inspired by this, I decided to create a little DOS program which an end-user could use to stop/start a service:
@ECHO OFF SETLOCAL enableextensions for /f "tokens=4" %%s in ('sc query OracleServiceXE ^| find /i "state"') do (SET _state=%%s) for /f "tokens=2" %%t in ('sc query OracleServiceXE ^| find /i "service_name"') do (SET _service_name=%%t) ECHO ================================ ECHO %_service_name% is %_state% ECHO ================================ if %_state%==RUNNING goto SRVC-R if %_state%==STOPPED goto SRVC-S :SRVC-R echo %_service_name% Is RUNNING, would you like to STOP it? Y/N set /p Input1= if /i "%Input1%"=="y" sc stop OracleServiceXE echo. sleep 10 for /f "tokens=4" %%s in ('sc query OracleServiceXE ^| find /i "state"') do (echo %_service_name% is %%s) pause exit /b :SRVC-S echo %_service_name% Is STOPPED, would you like to START it? Y/N set /p Input1= if /i "%Input1%"=="y" sc start OracleServiceXE echo. sleep 10 for /f "tokens=4" %%s in ('sc query OracleServiceXE ^| find /i "state"') do (echo %_service_name% is %%s) pause exit /b