如何一一运行某些CMD命令(以管理员身份)

问题描述:

我有一些要通过CMD(admin)运行的命令:ipconfig/flushdnsipconfig/注册域名ipconfig/发布ipconfig/更新netsh winsock重置有人可以告诉我怎么做吗?

I have a few commands I want to run through the CMD (admin): ipconfig/flushdns ipconfig /registerdns ipconfig /release ipconfig /renew netsh winsock reset Anyone can tell me how?

以下是对问题的解答:

Question of is sort answered here: Running cmd commands with Administrator rights

该代码可以重复(如下所示):

The code could be duplicated (as shown below):

 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();