Is there any way to get windows task manager detai

2019-02-24 08:47发布

问题:

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?

回答1:

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

exec master..xp_cmdshell 'TASKLIST'

Output:

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
.....

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