如何在 CMD 中检查某个服务是否正在运行 - 尤其是 MSSQL?
我需要使用 CMD 而不是通常的 service.msc gui 来执行此操作
答案1
您可以使用命令通过命令行检查服务是否正在运行sc query
。
例如,要检查 MSSQL 是否正在运行,您可以尝试:
sc query MSSQLSERVER
答案2
命令行,搜索所有 MSSQL 服务:
Wmic service where (PathName like '%Binn\\sqlservr%') get caption, name, startmode, state, PathName, ProcessId
输出:
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 Stopped
命令行,搜索命令路径如Binn\sqlservr
:
Wmic process where (ExecutablePath like '%Binn\\sqlservr%') get CommandLine, name, ProcessId
输出:
CommandLine Name ProcessId
"C:\App32\Microsoft SQL Server\MSSQL.4\MSSQL\Binn\sqlservr.exe" -sSQL2K5LOG sqlservr.exe 8288