Auto-stop DUN via VB.Net?

  • Thread starter Thread starter TofuTheGreat
  • Start date Start date
T

TofuTheGreat

Here's a good one for the gurus out there.

I'm building a custom application that will query a web-service to get
data. The users are broken into two groups. Group 1 is the in-office
staff that are connected to the network. Group 2 is the remote staff
that must connect via dial-up connection to the Internet to use the
web-service.

The user (a.k.a. boss) would like the application to automatically
close the dial-up connection if there hasn't been any activity for 10
minutes. Anyone like to share a way to programmatically launch a
dial-up connection and then close it from within my application? Even
pointing me to KB articles would be good.
 
Here's a good one for the gurus out there.

I'm building a custom application that will query a web-service to get
data. The users are broken into two groups. Group 1 is the in-office
staff that are connected to the network. Group 2 is the remote staff
that must connect via dial-up connection to the Internet to use the
web-service.

The user (a.k.a. boss) would like the application to automatically
close the dial-up connection if there hasn't been any activity for 10
minutes. Anyone like to share a way to programmatically launch a
dial-up connection and then close it from within my application? Even
pointing me to KB articles would be good.

Copied from Herfried's post from last year (google is great):

\\\

' Written by Herfried K. Wagner.
Public Class InternetDialer
Public Declare Function InternetAutodial Lib "wininet.dll" ( _
ByVal dwFlags As Int32, _
ByVal hwndParent As IntPtr _
) As Boolean

Private Const INTERNET_AUTODIAL_FORCE_ONLINE As Int32 = &H1
Private Const INTERNET_AUTODIAL_FORCE_UNATTENDED As Int32 = &H2
Private Const INTERNET_AUTODIAL_FAILIFSECURITYCHECK As Int32 = &H4
Private Const INTERNET_AUTODIAL_OVERRIDE_NET_PRESENT As Int32 = &H8

Private Declare Function InternetAutodialHangup Lib "wininet.dll" ( _
ByVal dwReserved As Int32 _
) As Boolean

Public Enum AutoDialOptions
ForceOnline = INTERNET_AUTODIAL_FORCE_ONLINE
ForceUnattended = INTERNET_AUTODIAL_FORCE_UNATTENDED
FailIfSecurityCheck = INTERNET_AUTODIAL_FAILIFSECURITYCHECK
OverrideNetPresent = INTERNET_AUTODIAL_OVERRIDE_NET_PRESENT
End Enum

Public Shared Sub Dialup(ByVal Options As AutoDialOptions)
Dialup(Options, IntPtr.Zero)
End Sub

Public Shared Sub Dialup(ByVal Options As AutoDialOptions, ByVal Parent
As Control)
Dialup(Options, Parent.Handle)
End Sub

Public Shared Sub Dialup( _
ByVal Options As AutoDialOptions, _
ByVal hwndParent As IntPtr _
)
If Not InternetAutodial(Options, hwndParent) Then
Throw _
New ApplicationException( _
"Error dialling the default internet connection." _
)
End If
End Sub

Public Shared Sub Hangup()
If Not InternetAutodialHangup(0) Then
Throw _
New ApplicationException( _
"Error disconnecting internet connection." _
)
End If
End Sub
End Class
///

HTH,
Mythran
 
Back
Top