powershellwindowfocusmicrosoft-file-explorer

How to Set an Open Explorer Window to be Topmost in PowerShell Without Extra Modules?


In PowerShell how can I set an open explorer window topmost without any extra modules

the explorer window is is c:\users\public\fonts

Regards

I found this one liner (New-Object -ComObject WScript.Shell).AppActivate((get-process notepad).MainWindowTitle) but it doesn't work for explorer.


Solution

  • Making a window topmost is different from activating it:


    It looks like activating a window by its title is what you're looking for:

    $null = (New-Object -ComObject WScript.Shell).AppActivate('c:\users\public\fonts')