I've been asked to write script that will monitor specific processes and notify someone when one or more of the processes goes down. All the processes have the same name so I'm collecting the PID using ProcessGetStats and _ProcessGetName. This works great. Now that I'm able to monitor the processes I've been asked to add into the information provided the user name that the process was running under. Each process is running under its own special user name. In the task manager the processes look s
Here's a simple example using WMI. There's prob better ways (dll call) but this is what I've got to contribute.
Func _ProcessOwner($pid=0,$hostname=".")
$objWMIService = ObjGet("winmgmts://" & $hostname & "/root/cimv2")
$colProcess = $objWMIService.ExecQuery("Select * from Win32_Process Where ProcessID ='" & $pid & "'")
For $objProcess In $colProcess
If $objProcess.ProcessID = $pid Then
$usr = 0
$objProcess.GetOwner($usr)
Return $usr
EndIf
Next
EndFunc