Google Code Prettify

[C#]實現PPPOE撥號與掛斷

廢話不多說了, 直接看 Code 吧!

撥接上網程式:

private void Connect(string In_EntryName, string In_UserName, string In_Password) {
     Process NetworkOpen_Process = new Process();
     NetworkOpen_Process.StartInfo.FileName = "rasdial";
     string ArgumentsString = string.Format("{0} {1} {2}", In_EntryName, In_UserName, In_Password);
     NetworkOpen_Process.StartInfo.Arguments = ArgumentsString;
     NetworkOpen_Process.Start();//執行
}

網路斷開程式:
private void Disconect() {
    Process NetworkClose_Process = new Process();
    NetworkClose_Process.StartInfo.FileName = "rasdial";
    NetworkClose_Process.StartInfo.Arguments = "/disconnect";
    NetworkClose_Process.Start();//執行
    NetworkClose_Process.WaitForExit();
}

判斷是否在連線狀態:

[DllImport("wininet")]
public static extern bool InternetGetConnectedState(
     ref uint lpdwFlags,
     uint dwReserved
    );
private bool isConnect() {
    uint flags = 0x0;
    return InternetGetConnectedState(ref flags, 0);
}

在撥接上網時要傳入:
     In_EntryName: 您撥接的設定名稱 (我個人是用下圖的ADSL)
     In_UserName: 您撥接的帳號
     In_Password: 您撥接的密碼


 撥接的設定畫面



怎能樣? 應該有清楚吧! ^_^