• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3820
  • Last Modified:

Monitor Process, CPU Usage and UserName

I'm looking to write a script that will query all processes, CPU usage and the username of the process.  I have found scripts that will give me the process and CPU usage, but not the username.  I am trying to automate a script that will look for processes that are using too much CPU and terminate them.  For example:

On a terminal server 10 users are running the same application:  'Office.exe'

All users instances of 'Office.exe' were running fine except for user 5.  User 5 has opened 4 instances of 'Office.exe' and each instance is using 25% CPU on a quad core system (all 4 cores are maxxed out).  This bogs down the server.  I would need the script to recognize the process and username that is associated with the process so it could terminate the process only for that user.  
Please help
  • 2
1 Solution
Hi, I'm not sure that WMI can give you the username info, but I would have a look at combining / filtering the outputs from the command
tasklist /v
and from the PSList (http://technet.microsoft.com/en-us/sysinternals/bb896682.aspx) command:
pslist -m <processname>

where <processname> could probably be piped from each process name in the tasklist /v output.

Would that give you enough info?


Or, you should be able to use this snippet to give you the owner of the processes:

strComputer = "."
strProcessList = ""
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" _
    & strComputer & "\root\cimv2")
Set colProcessList = objWMIService.ExecQuery _
    ("Select * from Win32_Process")
For Each objProcess in colProcessList
    colProperties = objProcess.GetOwner( _
    strProcessList = strProcessList & VbCr &_
      "Process " & objProcess.Name _
        & " is owned by " _
        & strUserDomain & "\" & strNameOfUser & "."
MsgBox strProcessList



Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now