02 Şub 2023
by Şerif Çiçek

How To Run A Program In c# As Administrator Permission

How To Run A Program In c# As Administrator Permission

if you want to start a program as administrator you can do it by triggering the following method


 public void RunProcessAsAdmin(string exepath, string txtworkingdir)

{

try

 {

System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();

      startInfo.UseShellExecute = true;

startInfo.WorkingDirectory = txtworkingdir;

          startInfo.FileName = exepath;

     startInfo.Verb = "runas";

     startInfo.ErrorDialog = true;

     Process process = System.Diagnostics.Process.Start(startInfo);          


     //process.WaitForExit();  //if wait for process;

}

catch (System.ComponentModel.Win32Exception ex)  

{

WriteToLog(ex.Message.ToString());


            }

            catch (Exception ex)

            {

                WriteToLog(ex.Message.ToString());

            }


        } 



usage:


RunProcessAsAdmin(txtExeRoot, txtworkingdir);


Add Comment
Yorum yazmak için lütfen üye olunuz