Reputation: 170
I seem to be running into a dead end here. I have a project that does the following:
This is working just fine, however what is NOT working is that when the form is shown, it does NOT activate.
Now, prior to me modifying the app.manifest to requireAdmin
, it was working fine. Any time the form was shown, boom it was active.
But now that i'm running the form as Administrator, given that I need to be able to control one of our other applications with it (that is ran as admin as well), the form comes up just fine, but doesn't activate.
I have tried:
- TopMost = true
inside of the Form_Load method
- Calling SetForegroundWindow
with the forms handle on Form_Load
- Calling ShowDialog
both on Form_Load and also tried it when the form was built.
- Calling Activate
on Form_Load as well as when the form was built
Here's my layout:
Again, without UAC and requireAdmin
inside of the app.manifest, this works fine. But once it is running as admin, nope, wont stay in front.
I know that MS has made the SetForegroundWindow
requirements much stricter with later versions of windows (Vista, 7, 8), but i really need to be able to make this form show as the top most, active window (like a context menu).
How can i do that properly?
Upvotes: 0
Views: 619
Reputation: 37192
You could split your program into two, a non-admin requiring half that sits in the tray and watches for the middle button, and the half that requires admin permission that you launch when the mouse button is pressed. The non-elevated half could then call SetForegroundWindow
or AllowSetForegroundWindow
as needed.
If you want to avoid a UAC prompt every time you can cache a COM elevation object via the CoCreateInstanceAsAdmin
method and use it repeatedly.
Upvotes: 1