Skip to content

Instantly share code, notes, and snippets.

@hoppfrosch
Created September 26, 2013 06:45
Show Gist options
  • Save hoppfrosch/6710611 to your computer and use it in GitHub Desktop.
Save hoppfrosch/6710611 to your computer and use it in GitHub Desktop.
Get information about running processes using WMI #ahk #script #function #wmi #com
; Description: Get Process properties via AHK using WMI
;
; Author: hoppfrosch - 20140206
;
; Credits
; * http://technet.microsoft.com/en-us/library/ee176712.aspx (by MSDN)
; * http://msdn.microsoft.com/en-us/library/windows/desktop/aa394372%28v=vs.85%29.aspx
; * http://http://www.autohotkey.com/board/topic/90385-drei-kleine-fragen (by Rohwedder)
; * http://www.autohotkey.com/board/topic/72817-how-to-obtain-%E2%80%9Cuser-name%E2%80%9D-from-running-processes/#entry465606 (by Lexikos)
PropertyList := "Caption,CommandLine,CreationClassName,CreationDate,CSCreationClassName,CSName,Description,ExecutablePath,"
. "ExecutionState,Handle,HandleCount,InstallDate,KernelModeTime,MaximumWorkingSetSize,MinimumWorkingSetSize,Name,"
. "OSCreationClassName,OSName,OtherOperationCount,OtherTransferCount,PageFaults,PageFileUsage,ParentProcessId,"
. "PeakPageFileUsage,PeakVirtualSize,PeakWorkingSetSize,Priority,PrivatePageCount,ProcessId,QuotaNonPagedPoolUsage,"
. "QuotaPagedPoolUsage,QuotaPeakNonPagedPoolUsage,QuotaPeakPagedPoolUsage,ReadOperationCount,ReadTransferCount,"
. "SessionId,Status,TerminationDate,ThreadCount,UserModeTime,VirtualSize,WindowsVersion,WorkingSetSize,"
. "WriteOperationCount,WriteTransferCount"
objWMIService := ComObjGet("winmgmts:{impersonationLevel=impersonate}!\\" . A_ComputerName . "\root\cimv2")
WQLQuery = Select * From Win32_Process
colProc := objWMIService.ExecQuery(WQLQuery)._NewEnum
While colProc[objProc]
Loop, Parse, PropertyList, `,
ProcInfo .= A_LoopField . ":`t" . objProc[A_LoopField] . "`n"
logfile = %A_ScriptDir%\ProcessInfo.txt
FileDelete, %logfile%
FileAppend, %ProcInfo%, %logfile%
Run, Notepad "%logfile%"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment