Get all windows of a process in powershell -
i want list windows of process, word. gives me main window:
get-process winword |where {$_.mainwindowtitle} |format-table id,name,mainwindowtitle –autosize
i want list document1 here.
id name mainwindowtitle
1616 winword document2 - microsoft word
is there way access windows other main one?
thanks bacon bits suggestion managed find solution, if have less cumbersome this, please share:
<# .synopsis enumerieren der vorhandenen fenster #> $typedef = @" using system; using system.text; using system.collections.generic; using system.runtime.interopservices; namespace api { public class winstruct { public string wintitle {get; set; } public int winhwnd { get; set; } } public class apidef { private delegate bool callbackptr(int hwnd, int lparam); private static callbackptr callbackptr = callback; private static list<winstruct> _winstructlist = new list<winstruct>(); [dllimport("user32.dll")] [return: marshalas(unmanagedtype.bool)] private static extern bool enumwindows(callbackptr lpenumfunc, intptr lparam); [dllimport("user32.dll", charset = charset.auto, setlasterror = true)] static extern int getwindowtext(intptr hwnd, stringbuilder lpstring, int nmaxcount); private static bool callback(int hwnd, int lparam) { stringbuilder sb = new stringbuilder(256); int res = getwindowtext((intptr)hwnd, sb, 256); _winstructlist.add(new winstruct { winhwnd = hwnd, wintitle = sb.tostring() }); return true; } public static list<winstruct> getwindows() { _winstructlist = new list<winstruct>(); enumwindows(callbackptr, intptr.zero); return _winstructlist; } } } "@ add-type -typedefinition $typedef -language csharpversion3 [api.apidef]::getwindows() | where-object { $_.wintitle -like "*word" } | sort-object -property wintitle | select-object wintitle,@{name="handle"; expression={"{0:x0}" -f $_.winhwnd}}
Comments
Post a Comment