2009年5月27日 星期三

vb.net 自動撥 ADSL (pppoe)

1.先設定好ADSL連線項目,名稱取名為 adsl


2. 在vb.net 裡面寫一段程式碼
Public Function Cmd(ByVal Command As String) As String
Dim process As New System.Diagnostics.Process()
process.StartInfo.FileName = "cmd.exe"
process.StartInfo.UseShellExecute = False
process.StartInfo.RedirectStandardInput = True
process.StartInfo.RedirectStandardOutput = True
process.StartInfo.RedirectStandardError = True
process.StartInfo.CreateNoWindow = True
process.Start()
process.StandardInput.WriteLine(Command)
process.StandardInput.WriteLine("exit")
Dim Result As String = process.StandardOutput.ReadToEnd()
process.Close()
Return Result
End Function

3.關鍵為 rasphone.exe
'自己去撥號
Cmd("rasphone.exe -d adsl")

至於怎麼偵測網路斷線就是自己的本領了,可以去ping中華電信的DNS,看看是不是活著,或者....
自己發揮

沒有留言:

張貼留言