C#.NET獲得撥號銜接的寬帶銜接辦法。本站提示廣大學習愛好者:(C#.NET獲得撥號銜接的寬帶銜接辦法)文章只能為提供參考,不一定能成為您想要的結果。以下是C#.NET獲得撥號銜接的寬帶銜接辦法正文
本文實例講述了C#.NET獲得撥號銜接的寬帶銜接辦法。分享給年夜家供年夜家參考。詳細以下:
該代碼直接可以用,我在XP VS2010 NET3.5上測試經由過程。
起首是ASDL的封裝
class SinASDL { //ASDL在注冊表中的寄存地位,這個是針對WinXP的, //不曉得Win7能否是這個,待驗證 private static String _adlskeys = @"RemoteAccess\Profile"; public static String adlskeys { get { return _adlskeys; } } /// <summary> /// 獲得本機的撥號稱號,也就是本機上一切的撥號 /// </summary> /// <returns></returns> public static String[] GetASDLNames() { RegistryKey RegKey = Registry.CurrentUser.OpenSubKey(adlskeys); if (RegKey != null) return RegKey.GetSubKeyNames(); else return null; } private String _asdlname = null; private ProcessWindowStyle _windowstyle = ProcessWindowStyle.Hidden; /// <summary> /// 實例化一個ASDL銜接 /// </summary> /// <param name="asdlname">ASDL稱號,如“寬帶銜接”</param> /// <param name="username">用戶名</param> /// <param name="password">暗碼</param> /// <param name="windowstyle">窗口顯示方法,默許為是以撥號進程</param> public SinASDL(String asdlname, String username = null, String password = null, ProcessWindowStyle windowstyle = ProcessWindowStyle.Hidden) { this.ASDLName = asdlname; this.Username = username; this.Password = password; this.WindowStyle = windowstyle; } /// <summary> /// 撥號稱號 /// </summary> public String ASDLName { get { return this._asdlname; } set { this._asdlname = value; } } /// <summary> /// 撥號過程的窗口方法 /// </summary> public ProcessWindowStyle WindowStyle { get { return this._windowstyle; } set { this._windowstyle = value; } } private String _username = null; //用戶名 private String _password = null; //暗碼 /// <summary> /// 用戶名 /// </summary> public String Username { get { return this._username; } set { this._username = value; } } /// <summary> /// 暗碼 /// </summary> public String Password { get { return this._password; } set { this._password = value; } } /// <summary> /// 開端撥號 /// </summary> /// <returns>前往撥號過程的前往值</returns> public int Connect() { Process pro = new Process(); pro.StartInfo.FileName = "rasdial.exe"; pro.StartInfo.Arguments = this.ASDLName + " " + this.Username + " " + this.Password; pro.StartInfo.WindowStyle = this.WindowStyle; pro.Start(); pro.WaitForExit(); return pro.ExitCode; } /// <summary> /// 端口銜接 /// </summary> /// <returns></returns> public int Disconnect() { Process pro = new Process(); pro.StartInfo.FileName = "rasdial.exe"; pro.StartInfo.Arguments = this.ASDLName + " /DISCONNECT"; pro.StartInfo.WindowStyle = this.WindowStyle; pro.Start(); pro.WaitForExit(); return pro.ExitCode; } }
上面是應用測試:
//SinASDL asdl = new SinASDL("寬帶銜接", "08793312221", "123456"); //寬帶銜接 //應用列舉到的第一個停止撥號 SinASDL asdl = new SinASDL(SinASDL.GetASDLNames()[0], "08793312221", "123456", System.Diagnostics.ProcessWindowStyle.Normal); if (asdl.Connect() == 0) { MessageBox.Show("Success"); } else { MessageBox.Show("Fail"); }
我本身測試的時刻是經由過程的。
假如電腦上不止一個撥號的,那末你可以用SinASDL.GetASDLNames()停止列舉。
願望本文所述對年夜家的C#法式設計有所贊助。