This article describes the broadband connection method of C#.NET to obtain dial-up connection. Share it for your reference. The details are as follows:
This code works directly, I tested it on XP VS2010 NET3.5.
First, the ASDL package
class SinASDL { //The storage location of ASDL in the registry is for WinXP. //I don't know if Win7 is this, waiting to be verified private static String _adlskeys = @"RemoteAccess\Profile"; public static String adlskeys { get { return _adlskeys; } } /// <summary> /// Get the dial name of the machine, that is, all dialing numbers on the machine /// </summary> /// <returns></returns> public static String[] GetASDLNames() { RegistryKey RegKey = (adlskeys); if (RegKey != null) return (); else return null; } private String _asdlname = null; private ProcessWindowStyle _windowstyle = ; /// <summary> /// Instantiate an ASDL connection /// </summary> /// <param name="asdlname">ASDL name, such as "Broadband Connection"</param> /// <param name="username">username</param> /// <param name="password">Password</param> /// <param name="windowsstyle">Window display mode, default is therefore dialing process</param> public SinASDL(String asdlname, String username = null, String password = null, ProcessWindowStyle windowstyle = ) { = asdlname; = username; = password; = windowstyle; } /// <summary> /// dial name /// </summary> public String ASDLName { get { return this._asdlname; } set { this._asdlname = value; } } /// <summary> /// window method of dialing process /// </summary> public ProcessWindowStyle WindowStyle { get { return this._windowstyle; } set { this._windowstyle = value; } } private String _username = null; //username private String _password = null; //password /// <summary> /// username /// </summary> public String Username { get { return this._username; } set { this._username = value; } } /// <summary> /// password /// </summary> public String Password { get { return this._password; } set { this._password = value; } } /// <summary> /// Start dialing /// </summary> /// <returns>Returns the return value of the dialing process</returns> public int Connect() { Process pro = new Process(); = ""; = + " " + + " " + ; = ; (); (); return ; } /// <summary> /// Port connection /// </summary> /// <returns></returns> public int Disconnect() { Process pro = new Process(); = ""; = + " /DISCONNECT"; = ; (); (); return ; } }
Here is the usage test:
//SinASDL asdl = new SinASDL("Broadband Connection", "08793312221", "123456");//Broadband connection//Dialize using the first enumerationSinASDL asdl = new SinASDL(()[0], "08793312221", "123456", ); if (() == 0) { ("Success"); } else { ("Fail"); }
I passed the test myself.
If there is more than one dialer on the computer, you can enumerate it with().
I hope this article will be helpful to everyone's C# programming.