1

Based on information from my previous question, I'm trying to learn wmic.

I'm playing around with trying to look at which processes are using the most resources on a remote server. What I've managed to come up with is near the bottom of this post. It works very well on my local machine, but when I psexec into a server (Windows 2003 or 2008) and try to run this command, it hangs nearly every time. I can't even ctrl+c to get it to stop. I used RDP (using a different username) to get into one of the machines where this command hangs. The username that sends the command from psexec shows two items listed in Task Manager, cmd and wmic. They've remained in Task Manager several hours after sending the command. When I end them, it frees up my console on my local machine.

I've tried looking up reasons this might be hanging, and I cannot find anything. I also asked one of my system admins, but those guys are always way too busy to help a lowly NOC guy (legitimately, though. They really are very busy). Any ideas as to what might be going wrong?

wmic path win32_perfformatteddata_perfproc_process where (PercentProcessorTime != 0) get Name, PercentProcessorTime, IDProcess
  • I might have found a related problem even if it's on 2012: support.microsoft I had many hanging WMIC.EXE visible in my task viewer – Boop Mar 24 '17 at 8:15
3

I'd strongly recommend moving away from WMIC.EXE, and use PowerShell instead. PowerShell lets you use RPC to access the remote server's WMI interface, negating the need for PsExec. Although PsExec is a useful tool, I'd only use it if absolutely necessary, as it creates a service on the remote server, the newly created remote service then spawns a process to run your code, and the service is then supposed to auto-delete. However, I've come across servers that have failed PsExec services, and numerous orphaned processes that have failed for one or another reason. So, with my preaching over, here's an equivalent using PowerShell:

Get-WmiObject -ComputerName "<REMOTE-SERVER-NAME>" -class Win32_PerfFormattedData_PerfProc_Process -Impersonation Impersonate -Filter "PercentProcessorTime != 0 and name != '_Total'" | Select-Object name, PercentProcessorTime, IDProcess
  • Well, I guess learning Powershell won't be a bad thing. Thank you for that, I'll play around with it. – duzzy Jul 7 '14 at 8:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.