【问题标题】:How to change IP of system problematically in a Windows service or console app [closed]如何在 Windows 服务或控制台应用程序中有问题地更改系统 IP [关闭]
【发布时间】:2012-12-06 04:42:04
【问题描述】:

我正在编写一个 C# 应用程序并想更改我的系统的 IP 地址。

我找到了这个命令

netsh interface ip set address name="Local Area Connection" static 192.168.1.191 255.255.255

但是我怎样才能在代码中做到这一点呢?

【问题讨论】:

  • 我想用 c# 来帮助我

标签: c# windows windows-services ip ip-address


【解决方案1】:

使用System.Diagnotics.Process 类,这样的东西应该可以工作。

string result;

Process p = new Process();
p.StartInfo.FileName = "netsh.exe";
p.StartInfo.Arguments = "interface ip add address name=\"Local Area Connection\" static 192.168.1.191 255.255.255";
p.StartInfo.UseShellExecute = false;
p.StartInfo.CreateNoWindow = true;
p.StartInfo.RedirectStandardOutput = true;
try
{
   p.Start();
   p.WaitForExit(30000);
   result = p.StandardOutput.ReadToEnd();
}
catch(Exception ex)
{
   result = ex.Message;
}

// check "result" variable for your results.

【讨论】:

  • 是的,您正在编写,但收到请求的操作需要提升(以管理员身份运行)。\n\r\n
  • 老兄,我的一些 rnd 对其进行了工作;)再次感谢
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-02-03
  • 2018-01-14
  • 2013-02-25
  • 1970-01-01
  • 2012-05-26
相关资源
最近更新 更多