How can you check in CMD if a particular service is running - Especially MSSQL?
I have a need to do it CMD and not the usual service.msc gui
2 Answers
You can check if a service is running via the command line with the sc query command.
For example, to check if MSSQL is running you might try:
sc query MSSQLSERVER 1 command line, search all MSSQL services:
Wmic service where (PathName like '%Binn\\sqlservr%') get caption, name, startmode, state, PathName, ProcessIdOutput:
Caption Name PathName ProcessId StartMode State
SQL Server (SQL2K5LOG) MSSQL$SQL2K5LOG "C:\App32\Microsoft SQL Server\MSSQL.4\MSSQL\Binn\sqlservr.exe" -sSQL2K5LOG 8288 Manual Running
SQL Server (SQLEXPRESS) MSSQL$SQLEXPRESS "C:\App64\Microsoft SQL Server\MSSQL10.SQLEXPRESS\MSSQL\Binn\sqlservr.exe" -sSQLEXPRESS 0 Disabled Stopped
SQL Server (SQLLOGPR) MSSQL$SQLLOGPR "C:\App64\Microsoft SQL Server\MSSQL10.SQLLOGPR\MSSQL\Binn\sqlservr.exe" -sSQLLOGPR 0 Disabled Stopped
SQL Server (MSSQLSERVER) MSSQLSERVER "C:\App64\Microsoft SQL Server\MSSQL.1\MSSQL\Binn\sqlservr.exe" -sMSSQLSERVER 0 Manual Stoppedcommand line, search command path like Binn\sqlservr:
Wmic process where (ExecutablePath like '%Binn\\sqlservr%') get CommandLine, name, ProcessIdOutput:
CommandLine Name ProcessId
"C:\App32\Microsoft SQL Server\MSSQL.4\MSSQL\Binn\sqlservr.exe" -sSQL2K5LOG sqlservr.exe 8288