Hello
Im making a application which needs some administrator priviliges. The thing is that this besides 7 will also run on XP.
Ive been told that changing in the app.manifest the requestedExecutionLevel is one step as this basically will require a admin
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
<!-- UAC Manifest Options
If you want to change the Windows User Account Control level replace the
requestedExecutionLevel node with one of the following.
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
<requestedExecutionLevel level="highestAvailable" uiAccess="false" />
Specifying requestedExecutionLevel node will disable file and registry virtualization.
If you want to utilize File and Registry Virtualization for backward
compatibility then delete the requestedExecutionLevel node.
-->
<requestedExecutionLevel level="highestAvailable" uiAccess="false" />
</requestedPrivileges>
But the other problem occures in the legacy world: On XP, ive been told this basically means nothing and I have to use a "IsInRole" method. Currently I have this:
static void Main()
{
// AppDomain myDomain = Thread.GetDomain();
// myDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal);
WindowsPrincipal myPrincipal = (WindowsPrincipal) Thread.CurrentPrincipal;
if (myPrincipal.IsInRole(WindowsBuiltInRole.User))
{
MessageBox.Show("You must be admin to run this");
}
else
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new FormPrincipal());
}
}
But it doesnt work (this is in the Program.cs). It simply doesnt allow me to run the program (7 or XP; Simply doesnt let me run and shows the message in the MessageBox).
Any tips?
Thanks!