This has bugged me for months now, and I can't seem to figure out. Today, I tried ChatGPT for hints on how to implement this, and it gave me some, but nothing works...
I have this code:
Code: Select all
Gui, aGui:New
Gui, aGui:Add, ListView, w1200 r10, Process Name|Command Line|PID|ParentID|File Name|DocCount
for proc in ComObjGet("winmgmts:").ExecQuery("Select * from Win32_Process where name = 'winword.exe'")
{
WinGetTitle, Title, % "ahk_pid " proc.ProcessId
Title := strsplit(Title, " - ").1 ; gets rid of the " - Word" part
; oword := ComObjGet("winmgmts:\\.\root\cimv2").ExecQuery("Select * from Win32_Process where ProcessId=" . proc.ProcessId).ItemIndex(0).GetOwner()
; oword := ComObjGet("winmgmts:").ExecQuery("Select * from Win32_Process where ProcessId=" . proc.ProcessId).ItemIndex(0).GetOwner()
oword := ComObjActive("Word.Application", proc.ProcessId)
; oword := ComObjGet("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2", "Process", proc.ProcessId)
docCount := oword.Documents.Count
LV_Add("", proc.Name, proc.CommandLine,proc.ProcessId, proc.ParentProcessId, Title, docCount)
}
LV_ModifyCol()
Gui, aGui:Show,, WinWord Process List
any help greatly appreciated