如何使用c#.net连接和断开互联网连接? [英] How to connect and disconnect internet connection using c#.net?

查看:74
本文介绍了如何使用c#.net连接和断开互联网连接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用c#.net windows应用程序有没有简单的方法?

解决方案

要进行连接,您应该在命令提示符中运行以下命令: code> ipconfig / renew

要断开连接,您应该运行以下命令: iponfig / release

您可以使用C#代码轻松完成此操作:

 使用系统。诊断;  //  将此项添加到代码文件的顶部 



 ProcessStartInfo info =  new  ProcessStartInfo(); 
info.FileName = ipconfig;
info.Arguments = / renew; // 或/如果要断开连接
info.WindowStyle = ProcessWindowStyle.Hidden;
流程p = Process.Start(info);
p.WaitForExit();



希望这会有所帮助。


除此之外,这些肯定会对您有所帮助:

使用C#启用禁用互联网连接 [ ^ ]

使用C#禁用网络 [ ^ ]

如何通过c#代码连接/断开互联网 [ ^ ]

Is there any easy way to do it with c#.net windows application?

解决方案

To connect, you should run the following command in the Command Prompt: ipconfig /renew
And to disconnect, you should run the following command: iponfig /release
You can do this easily from C# code:

using System.Diagnostics; // add this at the top of your code file


ProcessStartInfo info = new ProcessStartInfo();
info.FileName = "ipconfig";
info.Arguments = "/renew"; // or /release if you want to disconnect
info.WindowStyle = ProcessWindowStyle.Hidden;
Process p = Process.Start(info);
p.WaitForExit();


Hope this helps.


Along with above these will definitely help you:
Enable disable internet connection using C#[^]
Disabling Network using C#[^]
How to Connect/Disconnect Internet through c# code[^]


这篇关于如何使用c#.net连接和断开互联网连接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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