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
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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



Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Scripting Languages

From novice to tech pro — start learning today.