I want to ask for local administrator permission when pressing a button.
I'm intending to pop up an UAC prompt to ask for it.
I don't want to make the program only be ran as an administrator so I don't think I want to add an application manifest.
I tried to use a Process.Start()
on the executable with Verb = "runas"
, which pops up the UAC prompt, but that ends up running another copy of the application.
private void button1_Click(object sender, EventArgs e)
{
ProcessStartInfo startInfo = new ProcessStartInfo
{
FileName = Application.ExecutablePath,
Verb = "runas"
};
Process.Start(startInfo);
if(//permission granted)
{
//code
}
else
{
MessageBox.Show("Permission not granted");
}
}
I also tried to use PrincipalPermissions class but didn't call the prompt I wanted to.