I'm experiencing an unexpected behavior with a WPF window that's created with WS_EX_TOOLWINDOW style when the application is launched with UI Access token privileges.
Issue Description: A window with WS_EX_TOOLWINDOW style unexpectedly appears in Alt+Tab after explorer.exe is restarted, but only when the application is launched with UI Access token. This doesn't occur when running the application directly.
Steps to Reproduce:
- Start WPF application through a service using SetTokenInformation with TokenUIAccess
- Create transparent, topmost window with WS_EX_TOOLWINDOW style
- Kill explorer.exe from Task Manager (Details tab)
- Start explorer.exe using "Run new task"
- Press Alt+Tab - window appears despite WS_EX_TOOLWINDOW style
Window Styles Verification: I verified using Spy++ that the styles remain unchanged after explorer.exe restart: .png
The image shows Window Styles (0x680000) and Extended Styles (0x80A8) remain consistent before and after reproducing the issue, confirming WS_EX_TOOLWINDOW is still applied.
Code:
// Setting UI Access token
uint dwUIAccess = 1;
SetTokenInformation(hUserToken, TOKEN_INFORMATION_CLASS.TokenUIAccess, ref dwUIAccess, sizeof(uint));
// Window styles
var hwnd = new WindowInteropHelper(this).Handle;
var extendedStyle = GetWindowLong(hwnd, GWL_EXSTYLE);
SetWindowLong(hwnd, GWL_EXSTYLE, extendedStyle | WS_EX_TOOLWINDOW | WS_EX_TRANSPARENT);