GreatWest Posted September 14, 2009 Share Posted September 14, 2009 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 something like this: Image Name User Name CPU Mem Usage w3wp.exe ETPTL1 00 350,764 K w3wp.exe ETPTL3 00 415,264 K w3wp.exe ETPTL0 00 123,232 K w3wp.exe ETPTL5 00 239,293 K and so on, up to about 30 different user ID's to run each process. Does anyone know of a way to get the User Name information? This is the only way I can figure to identify which process died. Each User Name is tied to a specific site and will recycle and start back up with in about 60 seconds. So finding out which process and site went down is what I'm trying to record. Any ideas? Thanks, GW Link to comment Share on other sites More sharing options...
spudw2k Posted September 14, 2009 Share Posted September 14, 2009 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 Spoiler Things I've Made: Always On Top Tool ◊ AU History ◊ Deck of Cards ◊ HideIt ◊ ICU ◊ Icon Freezer ◊ Ipod Ejector ◊ Junos Configuration Explorer ◊ Link Downloader ◊ MD5 Folder Enumerator ◊ PassGen ◊ Ping Tool ◊ Quick NIC ◊ Read OCR ◊ RemoteIT ◊ SchTasksGui ◊ SpyCam ◊ System Scan Report Tool ◊ System UpTime ◊ Transparency Machine ◊ VMWare ESX Builder Misc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retrieve SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose Array Projects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalc Cool Stuff: AutoItObject UDF ◊ Extract Icon From Proc ◊ GuiCtrlFontRotate ◊ Hex Edit Funcs ◊ Run binary ◊ Service_UDF Link to comment Share on other sites More sharing options...
GreatWest Posted September 14, 2009 Author Share Posted September 14, 2009 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 Thank you for providing the code. This is much more advanced than I am capable of right now but there's only one way to learn, right? I'll work with it and see if I can get it to provide the information I need. Thanks again. GW Link to comment Share on other sites More sharing options...
GreatWest Posted September 14, 2009 Author Share Posted September 14, 2009 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 Got it working without too much trouble. Thanks! This is going to work great. Todd Link to comment Share on other sites More sharing options...
PsaltyDS Posted September 14, 2009 Share Posted September 14, 2009 Thank you for providing the code. This is much more advanced than I am capable of right now but there's only one way to learn, right? I'll work with it and see if I can get it to provide the information I need. Thanks again.GWThere is a function already completed in Example Scripts called _ProcessListProperties().The bird that wrote it is really good-looking, so it must work. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
spudw2k Posted September 15, 2009 Share Posted September 15, 2009 There is a function already completed in Example Scripts called _ProcessListProperties().The bird that wrote it is really good-looking, so it must work. Yea, looks good even though penguins don't fly. couldn't resist the bird pun.GW, Psalty's code provides additional process information. Maybe overkill for what you need, but still neat and useful. Perhaps just the Owner func will work in your case, as my code uses the same mechanisms (WMI), but I recommend learning from his code too....The Error handler (COM) can be particularly useful if you anticipate performing functions the, "might fail." Spoiler Things I've Made: Always On Top Tool ◊ AU History ◊ Deck of Cards ◊ HideIt ◊ ICU ◊ Icon Freezer ◊ Ipod Ejector ◊ Junos Configuration Explorer ◊ Link Downloader ◊ MD5 Folder Enumerator ◊ PassGen ◊ Ping Tool ◊ Quick NIC ◊ Read OCR ◊ RemoteIT ◊ SchTasksGui ◊ SpyCam ◊ System Scan Report Tool ◊ System UpTime ◊ Transparency Machine ◊ VMWare ESX Builder Misc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retrieve SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose Array Projects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalc Cool Stuff: AutoItObject UDF ◊ Extract Icon From Proc ◊ GuiCtrlFontRotate ◊ Hex Edit Funcs ◊ Run binary ◊ Service_UDF Link to comment Share on other sites More sharing options...
GreatWest Posted September 16, 2009 Author Share Posted September 16, 2009 Yea, looks good even though penguins don't fly. couldn't resist the bird pun.GW, Psalty's code provides additional process information. Maybe overkill for what you need, but still neat and useful. Perhaps just the Owner func will work in your case, as my code uses the same mechanisms (WMI), but I recommend learning from his code too....The Error handler (COM) can be particularly useful if you anticipate performing functions the, "might fail."GREAT! I'll check that out as there is more information that we could use if we had access to it. Maybe that code will help get what we need. I really appreceate all the help. I really like the power of AutoIT and the help on this Forum is really great. I recently went through a college Java course and was a member of several Java forums. I must say that the help and lack of flaming here in the AutoIT forum is one of the reasons I enjoy this application so much. I was bombarded by flames by many of the Java developers, though a few were very helpful. I'm an old structured C/C++ programmer (haven't touched it in better than 10 years though) so I fell right into AutoIT without any problem, unlike Java. That visual programming method just doesn't work for me at all. I did pass my course with a "B" so I guess I didn't do too bad. The really funny part is that the instructor had never done any programming in a structured language before. She continually made comments about how visual programming could do this or that but the same could not be done in structured programming. I'm talking about simple things like functions and using modular design and such. I'll stick with AutoIT. To date it has done just about everything I've needed it to do. Now if someone can write up a library that will interface to MS SharePoint, then I'd be on cloud nine!Thanks again for all the help. I haven't work with AutoIT for about a year now so I'm just getting back into it, and enjoying its simple but powerful capabilities. I just need more practice so I can learn more about the code provided, how it works and all. Again, greatly apprceated.GW Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now