google / UIforETW

User interface for recording and managing ETW traces
https://randomascii.wordpress.com/2015/04/14/uiforetw-windows-performance-made-easier/
Apache License 2.0
1.55k stars 201 forks source link

UIforETW shortcut doesn't launch from within a folder named 'UI for ETW' #147

Closed eugenesvk closed 3 years ago

eugenesvk commented 3 years ago

A UIforETW.lnk shortcut created from a ...\etwpackage\bin\UIforETW.exe file doesn't lanch the UIforETW app if this shortcut is placed in a folder named UI for ETW — the shortcut fails right after asking for elevated permissions. The same shortcut placed in a different folder (or if the same folder is renamed) works just fine

Windows 10.0.19042.0 etwpackage1.54.zip

randomascii commented 3 years ago

Thanks for the report. This bug is kind of hilarious. At first I thought that the spaces in the folder were the problem, but they aren't. Well, not really. That is, if you remove the spaces then the problem goes away, but it also goes away if you just remove one space, or if you add more.

The problem is that UIforETW looks for a previously running copy of itself and activates itself if it finds one. And it does that with this code:

HWND prevWindow = FindWindow(NULL, L"UI for ETW");
if (prevWindow)
{
    // Only allow one copy to be running at a time.
    SetForegroundWindow(prevWindow);
}

In your scenario the name of the Explorer window is "UI for ETW" so the explorer window is found and activated.

I should be using a clearly unique mutex or some-such, or else checking what process owns the window, or something. Anyway, that's the problem.

Pull requests welcome, or else I'll get around to fixing it at some point. Thanks again.

randomascii commented 3 years ago

Link to the problematic code, which was there in the very first commit:

https://github.com/google/UIforETW/blob/main/UIforETW/UIforETW.cpp#L194

randomascii commented 3 years ago

In addition to the obvious workaround of renaming the folder you can also workaround this by configuring explorer to display full path names in window titles.

Fixing this will be easy, but I don't know when I'll do a new release.

randomascii commented 3 years ago

This fix will ship in the next release.

eugenesvk commented 3 years ago

I've added an extra fix that would not switch to an open folder with the same name, but uniquely identify only the duplicate UIforETW instance via a unique window message. This should fully cover this issue