Articles → .NET → Open Application In Admin Mode When Deploy In Clickonce Deployment

Open Application In Admin Mode When Deploy In Clickonce Deployment









var wi = System.Security.Principal.WindowsIdentity.GetCurrent();
var wp = new WindowsPrincipal(wi);

if (!wp.IsInRole(WindowsBuiltInRole.Administrator)) {
  var processInfo = new System.Diagnostics.ProcessStartInfo(System.Reflection.Assembly.GetExecutingAssembly().CodeBase);

  // The following properties run the new process as administrator
  processInfo.UseShellExecute = true;
  processInfo.Verb = "runas";

  // Start the new process
  try {
    System.Diagnostics.Process.Start(processInfo);
  } catch (Exception) {
    // The user did not allow the application to run as administrator
    System.Windows.MessageBox.Show("Sorry, this application must be run as Administrator.");
  }

  // Shut down the current process
  Application.Current.Shutdown();
}



Posted By  -  Karan Gupta
 
Posted On  -  Tuesday, April 21, 2020

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250