本文主要是介绍利用DotRas实现ADSL断线并自动拨号,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
C#自动换IP,很多都是要弹拨号窗口的,利用dotras可以实现不弹窗
using DotRas;
private bool changeip()
{
try
{
string mypbk = RasPhoneBook.GetPhoneBookPath(RasPhoneBookType.AllUsers).ToString();
RasConnection myconn = RasConnection.GetActiveConnectionByName("adsl", mypbk);
myconn.HangUp();
RasDialer dialer = new RasDialer();
dialer.DialCompleted += new EventHandler<DialCompletedEventArgs>(dialer_DialCompleted);
dialer.EntryName = "adsl";
dialer.PhoneNumber = "";
dialer.AllowUseStoredCredentials = true;
dialer.PhoneBookPath = RasPhoneBook.GetPhoneBookPath(RasPhoneBookType.AllUsers);
dialer.Timeout = 5000;
rasdone = false;
RasHandle myras= dialer.Dial();
while(myras.IsInvalid)
{
Thread.Sleep(1000);
myras = dialer.Dial();
}
return true;
}
catch (Exception ex)
{
writeerr("[changeip]"+ex.Message);
return false;
}
}
这篇关于利用DotRas实现ADSL断线并自动拨号的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!