If you create Explorer windows programmatically, it is a different story - see next point. In other words: If you only ever open File Explorer windows interactively, you either have one ( Launch folder windows in a separate process OFF) or up to two ( Launch folder windows in a separate process ON) Explorer processes. ON: the first window you create interactively spawns one new Explorer process and all subsequently opened windows are then owned by that same new process. OFF (the default): all windows you create interactively are owned by the Explorer shell process - no new process is created. If File Explorer's Launch folder windows in a separate process view option is: If multiple users are logged on interactively (whether remotely or not), each such user may have one or more Explorer processes running, as described below.Īn interactively logged-on user has at least one Explorer process, which owns the taskbar and the desktop - it may or may not have actual File Explorer windows open let's call it the Explorer shell process. ? MainWindowHandle -eq ($helperType::FindWindow("Shell_TrayWnd", ''))Īs for when multiple File Explorer processes may exist (based on trial and error - do tell me if I got things wrong): # via window class "Shell_TrayHwnd" and an empty title. Public static extern IntPtr FindWindow(string lpszClass, string Locate the explorer.exe process that created the taskbar, $helperType = Add-Type -PassThru -Name "WinApiHelper$PID" -MemberDefinition SetLastError=true)] # Define a helper type and method for getting a window's handle ![]() Tip of the hat to Klaidonis for helping me simplify the code. ![]() Using Add-Member -MemberDefinition, you can define a helper type and method that finds the handle (HWND) of the process that owns the taskbar window, utilizing a P/Invoke signature to call a Windows API functions note that you'll incur an on-demand compilation performance penalty the first time you call this in a session. If other users could be logged on and you must limit the processes inspected to the current user's, run the following from an elevated console: Get-Process -IncludeUserName explorer | MainWindowTitle property of the taskbar-owning File Explorer instance reflecting the taskbar's window title, which happens to be empty, unlike the title of actual File Explorer windows - this appears to be the case on at least Windows 10 and Windows 7 (haven't tried others): Get-Process explorer | ? MainWindowTitle -eq '' # returns taskbar-owning Explorer process ![]() A slightly more concise alternative to veefu's helpful answer:
0 Comments
Leave a Reply. |