Revision: 84
http://pymoul.svn.sourceforge.net/pymoul/?rev=84&view=rev
Author: tiran
Date: 2007-01-26 08:40:35 -0800 (Fri, 26 Jan 2007)
Log Message:
-----------
Add two other modules about process infos (could be useful but I have to test them)
Added Paths:
-----------
pymoul/trunk/src/moul/osdependent/win32/enumprocesses.py
pymoul/trunk/src/moul/osdependent/win32/processinfo.py
Added: pymoul/trunk/src/moul/osdependent/win32/enumprocesses.py
===================================================================
--- pymoul/trunk/src/moul/osdependent/win32/enumprocesses.py (rev 0)
+++ pymoul/trunk/src/moul/osdependent/win32/enumprocesses.py 2007-01-26 16:40:35 UTC (rev 84)
@@ -0,0 +1,63 @@
+"""
+Enumerates active processes as seen under windows Task Manager on Win NT/2k/XP using PSAPI.dll
+(new api for processes) and using ctypes.Use it as you please.
+
+Based on information from http://support.microsoft.com/default.aspx?scid=KB;EN-US;Q175030&ID=KB;EN-US;Q175030
+
+By Eric Koome
+email ek...@ya...
+license GPL
+"""
+#http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/305279
+#Title: getting process information on windows
+#Submitter: Eric Koome (other recipes)
+#Last Updated: 2004/09/22
+#Version no: 1.3
+#Category:
+
+from ctypes import *
+
+#PSAPI.DLL
+psapi = windll.psapi
+#Kernel32.DLL
+kernel = windll.kernel32
+
+def EnumProcesses():
+ arr = c_ulong * 256
+ lpidProcess= arr()
+ cb = sizeof(lpidProcess)
+ cbNeeded = c_ulong()
+ hModule = c_ulong()
+ count = c_ulong()
+ modname = c_buffer(30)
+ PROCESS_QUERY_INFORMATION = 0x0400
+ PROCESS_VM_READ = 0x0010
+
+ #Call Enumprocesses to get hold of process id's
+ psapi.EnumProcesses(byref(lpidProcess),
+ cb,
+ byref(cbNeeded))
+
+ #Number of processes returned
+ nReturned = cbNeeded.value/sizeof(c_ulong())
+
+ pidProcess = [i for i in lpidProcess][:nReturned]
+
+ for pid in pidProcess:
+
+ #Get handle to the process based on PID
+ hProcess = kernel.OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ,
+ False, pid)
+ if hProcess:
+ psapi.EnumProcessModules(hProcess, byref(hModule), sizeof(hModule), byref(count))
+ psapi.GetModuleBaseNameA(hProcess, hModule.value, modname, sizeof(modname))
+ print "".join([ i for i in modname if i != '\x00'])
+
+ #-- Clean up
+ for i in range(modname._length_):
+ modname[i]='\x00'
+
+ kernel.CloseHandle(hProcess)
+
+if __name__ == '__main__':
+ EnumProcesses()
\ No newline at end of file
Property changes on: pymoul/trunk/src/moul/osdependent/win32/enumprocesses.py
___________________________________________________________________
Name: svn:eol-style
+ native
Added: pymoul/trunk/src/moul/osdependent/win32/processinfo.py
===================================================================
--- pymoul/trunk/src/moul/osdependent/win32/processinfo.py (rev 0)
+++ pymoul/trunk/src/moul/osdependent/win32/processinfo.py 2007-01-26 16:40:35 UTC (rev 84)
@@ -0,0 +1,34 @@
+#http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/303339
+#Title: getting process information on windows
+#Submitter: John Nielsen (other recipes)
+#Last Updated: 2004/09/03
+#Version no: 1.0
+#Category: System
+
+import win32pdh, string, win32api
+
+def procids():
+ #each instance is a process, you can have multiple processes w/same name
+ junk, instances = win32pdh.EnumObjectItems(None,None,'process', win32pdh.PERF_DETAIL_WIZARD)
+ proc_ids=[]
+ proc_dict={}
+ for instance in instances:
+ if instance in proc_dict:
+ proc_dict[instance] = proc_dict[instance] + 1
+ else:
+ proc_dict[instance]=0
+ for instance, max_instances in proc_dict.items():
+ for inum in xrange(max_instances+1):
+ hq = win32pdh.OpenQuery() # initializes the query handle
+ path = win32pdh.MakeCounterPath( (None,'process',instance, None, inum,'ID Process') )
+ counter_handle=win32pdh.AddCounter(hq, path)
+ win32pdh.CollectQueryData(hq) #collects data for the counter
+ type, val = win32pdh.GetFormattedCounterValue(counter_handle, win32pdh.PDH_FMT_LONG)
+ proc_ids.append((instance,str(val)))
+ win32pdh.CloseQuery(hq)
+
+ proc_ids.sort()
+ return proc_ids
+
+
+print procids()
\ No newline at end of file
Property changes on: pymoul/trunk/src/moul/osdependent/win32/processinfo.py
___________________________________________________________________
Name: svn:eol-style
+ native
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|