My app uses ClickOnce tehcnology. Today I needed to run it as administrator. I modified the manifest file from
private void Form1_Load(object sender, EventArgs e)
{
if (WindowsIdentity.GetCurrent().Owner == WindowsIdentity.GetCurrent().User) // Check for Admin privileges
{
try
{
this.Visible = false;
ProcessStartInfo info = new ProcessStartInfo(Application.ExecutablePath); // my own .exe
info.UseShellExecute = true;
info.Verb = "runas"; // invoke UAC prompt
Process.Start(info);
}
catch (Win32Exception ex)
{
if (ex.NativeErrorCode == 1223) //The operation was canceled by the user.
{
MessageBox.Show("Why did you not selected Yes?");
Application.Exit();
}
else
throw new Exception("Something went wrong :-(");
}
Application.Exit();
}
else
{
// MessageBox.Show("I have admin privileges :-)");
}
}