2017-08-27 2 views
-1

Ich habe ein paar Befehle, die ich durch den CMD (Admin) ausführen möchte: ipconfig/flushdns ipconfig /registerdns ipconfig /release ipconfig /renew netsh winsock reset Jeder kann mir sagen, wie?Wie man einige CMD-Befehle nacheinander ausführt (als Admin)

+1

Mögliches Duplikat von [Prozessprivileg programmgesteuert erhöhen?] (Https://stackoverflow.com/questions/133379/elevating-process-privilege-programmatisch) – Vanna

Antwort

0

Frage der Art hier beantwortet wird: Running cmd commands with Administrator rights

Der Code könnte dupliziert werden (siehe unten):

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

Das führt die CMD-Befehle als Administrator aus, richtig? (Auch wenn der Benutzer nicht "run as administrator" gewählt hat) – Leviathan

+0

Und es ist ein Fehler auf: process2.StartInfo2 = startInfo2; – Leviathan

+1

Sollte process2.StartInfo = startInfo2 sein – JSWulf

0

Wenn Sie schauen, Powershell zu verwenden, können Sie ein Skript erstellen, die Ihre Befehle so etwas wie dieses gehören wird:

& "command 1"; & "command 2"; usw.

Verwandte Themen