Answer the question
In order to leave comments, you need to log in
How to run an external program (for example, the steam client) in C#?
I am writing a program. I stopped at ignorance of how to run a separate program on behalf of the admin, I tried to find it on the Internet, but alas I didn’t find it, or I found it, but the code got bugged, or the launch of the program itself written in C # on behalf of the admin.
Answer the question
In order to leave comments, you need to log in
Simple option:
private void button1_Click(object sender, EventArgs e)
{
ProcessStartInfo info = new ProcessStartInfo(@"C:\Windows\Notepad.exe");
info.UseShellExecute = true;
info.Verb = "runas";
Process.Start(info);
}
private void button1_Click(object sender, EventArgs e)
{
const int ERROR_CANCELLED = 1223; //The operation was canceled by the user.
ProcessStartInfo info = new ProcessStartInfo(@"C:\Windows\Notepad.exe");
info.UseShellExecute = true;
info.Verb = "runas";
try
{
Process.Start(info);
}
catch (Win32Exception ex)
{
if (ex.NativeErrorCode == ERROR_CANCELLED)
MessageBox.Show("Why you no select Yes?");
else
throw;
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question