我可以检查当前通过 SSMS 运行的服务吗?

use*_*687 6 sql-server ssms

我想通过在 SSMS 上运行脚本/查询来检查哪些服务已启动,哪些尚未启动。

Aar*_*and 6

您可以使用 CLR 或 PowerShell 执行此操作。在 PowerShell 中,您可以使用诸如Get-Process或 之类的东西Get-Service来获取其中的一些信息。使用 C#,您可以查看此答案,但我不知道 SQLCLR 的任何现成代码。请注意,使用 PowerShell,您需要在远程计算机的上下文中运行命令,例如

Invoke-Command -ComputerName RemoteComputerName { Get-Service }

// or if your version of PS is modern enough:

Get-Service -ComputerName RemoteComputerName
Run Code Online (Sandbox Code Playgroud)

您还可以使用xp_cmdshell的调用之类的东西tasklistnet startwmic或第三方之类的Process Explorer(虽然我没有试过来调用通过命令行):

EXEC master..xp_cmdshell 'tasklist';
EXEC master..xp_cmdshell 'net start';
EXEC master..xp_cmdshell 'wmic service get';
Run Code Online (Sandbox Code Playgroud)

后者有更有价值的信息,但输出绝对可怕。

当然,这一切都假设您和/或 SQL Server 服务帐户具有调用这些函数的足够权限。

(摘自我对 SO 上类似问题的回答。)