有没有办法通过 tsql 获取 windows 任务管理器的详细信息?

2022-01-15 00:00:00 sql windows-10 tsql sql-server

我无法访问客户端的 Windows 远程机器,我只通过 tsql 连接他们的数据库服务器.我需要检查哪些进程占用更多内存并通知他们.是否有任何 tsql 查询来获取 windows 进程?

I do not have access to the client's windows remote machine,I connect their database server through tsql only.I need to check what processes taking more memory and inform them. Is there any tsql query to get windows processes?

推荐答案

是的,有可能.您可以通过 TASKLIST 命令调用 TASKLIST 命令msdn.microsoft.com/en-us/library/ms175046.aspx" rel="noreferrer">xp_cmdshell:

Yes, it is possible. You can call TASKLIST command via xp_cmdshell:

exec master..xp_cmdshell 'TASKLIST'

输出:

Image Name                     PID Session Name        Session#    Mem Usage
========================= ======== ================ =========== ============
System Idle Process              0                            0          4 K
System                           4                            0        140 K
smss.exe                       212                            0        956 K
csrss.exe                      332                            0      5,560 K
.....
sqlservr.exe                  1492                            0     92,012 K
sqlservr.exe                  1532                            0     95,928 K
.....

注意:您应该拥有正确的权限和服务器配置选项来运行 xp_cmdshell.阅读 MSDN 中的备注部分以了解如何启用 xp_cmdshell

Note: you should have the correct permissions and Server configuration options to run xp_cmdshell. Read the remarks section in MSDN to understand how to enable xp_cmdshell

相关文章