您可以使用 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的调用之类的东西tasklist
,net start
,wmic
或第三方之类的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 上类似问题的回答。)
归档时间: |
|
查看次数: |
1850 次 |
最近记录: |