问题
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
来源:https://stackoverflow.com/questions/42640548/is-there-any-way-to-get-windows-task-manager-details-through-tsql