J'ai quelques commandes que je veux exécuter via le CMD (admin): ipconfig/flushdns ipconfig /registerdns ipconfig /release ipconfig /renew netsh winsock reset
Quelqu'un peut me dire comment?Comment exécuter certaines commandes CMD une par une (en tant qu'admin)
-1
A
Répondre
0
Question de réponse est un peu ici: Running cmd commands with Administrator rights
Le code pourrait être dupliqué (comme indiqué ci-dessous):
System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new
System.Diagnostics.ProcessStartInfo();
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
startInfo.FileName = "cmd.exe";
startInfo.Arguments = "/C ipconfig /flushdns";
startInfo.Verb = "runas";
process.StartInfo = startInfo;
process.Start();
System.Diagnostics.Process process2 = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo2 = new
System.Diagnostics.ProcessStartInfo();
startInfo2.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
startInfo2.FileName = "cmd.exe";
startInfo2.Arguments = "/C ipconfig /renew";
startInfo2.Verb = "runas";
process2.StartInfo = startInfo2;
process2.Start();
0
Si vous cherchez à utiliser powershell, vous pouvez créer un script qui comprendra vos commandes quelque chose comme ceci:
& "command 1";
& "command 2";
etc.
Copie possible de [Elevating process privilege programatically?] (Https://stackoverflow.com/questions/133379/elevating-process-privilege-programmatically) – Vanna