Reputation: 433
I'm using this line in the app.manifest in order to raise an UAC prompt that demands administrative privileges in order for my program to run:
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
It works. However, I found out that if the program is executed in a standard user account and UAC is turned-off, the program still runs - without administrative privileges -.
What I want, is to prevent it from running in this scenario. Instead, it should give a message like: "Sorry, this program requires administrative privileges to run". And then it should close itself.
Most questions I found here in SO, are about how to elevate an application when UAC is turned off. That's not what I'm searching.
Thanks in advance for your help!
Upvotes: 3
Views: 297
Reputation: 1917
You have to check if your user is administrator with this:
if (!WindowsPrincipal.IsInRole(WindowsBuiltInRole.Administrator))
{
// show messagebox "Sorry, this program requires administrative privileges to run"
Application.Exit();
}
Upvotes: 3