GUI app generated from LocalSystem service (via CreateProcessAsUser) has no focus
I created a service that displays a splash screen on a specific user's desktop and only when that user logs in (kiosk user).
This splash screen, after entering a valid code, will inform the service about this and the service will go to sleep in x times (depending on the code).
The screensaver just closes. Now, when the service wakes up, it sees that the splash no longer exists, and so start it.
This all works, the only problem is that the running application has no focus i.e. if i work in notepad and time drags on, splash screen will be displayed full screen (full screen).
I only need to worry about Windows Vista, I am coding in Python using win32 extensions, but I believe this problem is with CreateProcessAsUser when called from LocalSystem account.
Update:
The "problem" is actually a purposeful restriction to prevent "annoying" apps like mine from stealing focus.
You can change the behavior by setting: win32gui.SystemParametersInfo (win32con.SPI_SETFOREGROUNDLOCKTIMEOUT, 0, 0) which is equivalent when temporarily setting the registry value: HKEY_CURRENT_USER \ Control Panel \ Desktop \ ForegroundLockTimeout This must be done as the user himself, so either create it in the application that you are launching, or create a launch assistant for the application you want to launch.
However, the application might want to prevent focus stealing by using some API call that I don't remember right now.
Probably a good solution would be to find all the window handles currently from that user and then use each of those handles to use win32gui.ShowWindow (handle, command) to minimize it.
Even though setting the locktimeout parameter was sufficient for this particular problem.
If anyone is wondering how I managed to launch the desktop application from the service, here is the link to the code .
a source to share
For various very legitimate reasons, Microsoft would rather not see the service launching the application and stealing focus, however I found the following work around to accomplish what I want.
The original intent is for a kiosk-like app to be tagged with a splash-saver-like pass code that, when entering an 8-character code, closes the splash screen for a period of time, as in the specified parot. Initially, the actual application to use was launched in the autorun folder.
However, I now rewrote it to run from my service, that way I can hide the application by starting the helper application from the service, which just hides the program and starts the splash screen, returns to its previous state after exiting the splash screen.
a source to share
Have you tried starting other processes besides your own from the service to see if this is focusing? How to notepad and see if it steals focus from your browser? If possible, it is a program that can return focus when it starts.
Otherwise, I can use the wShowWindow attribute from the STARTUPINFO structure pointed to by lpStartupInfo, which should control it. You also need STARTF_USESHOWWINDOW in dwFlags to use nShowWindow. The values โโshould be SW_SHOW, I think they are listed for the ShowWindow function if you want to try others.
a source to share