如何一一运行某些CMD命令(以管理员身份) [英] How to run some CMD commands one by one (As admin)

查看:85
本文介绍了如何一一运行某些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();

这篇关于如何一一运行某些CMD命令(以管理员身份)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆