• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 352
  • Last Modified:

Blocking the internet with Vb 2005

Hi all what i am waiting to do is write a little app where at 9:30 pm to 6:30pm the computer where the app is installed stops all internet access including msn

Can someone please give me a hand where to start
0
awolarczuk
Asked:
awolarczuk
  • 2
  • 2
1 Solution
 
aherpsCommented:
Hi,

This answer:

http://www.experts-exchange.com/Programming/System/Windows__Programming/Q_22812895.html

Allows you to disable network cards programatically.

You could have it hooked up to a Timer and enable as appropriate to meet your conditions.
0
 
awolarczukAuthor Commented:
mate thanks but this is for c and didnt covert like it said it would i am working in vb 2005, is there anything more that you know of
0
 
aherpsCommented:
Hi,

If you scroll down, there is a VB.NET conversion kindly provided by TheLearnedOne as follows:
VB.NET translation:
 
' Add a COM reference to 'Microsoft Shell Controls And Automation' to the project. 
' Source: 
' http://channel9.msdn.com/ShowPost.aspx?PostID=158556 
' http://channel9.msdn.com/Photos/ZippedFiles/158556_ToggleNic.zip 
 
Imports System
Imports System.IO
Imports System.Threading
Imports Shell32
 
Public Enum AdapterError
  Success
  ConnectionNotFound
  ConnectionsFolderNotFound
  ConnectionAlreadyOpen
  ConnectionAlreadyClosed
End Enum
 
Public Class NetworkAdapterState
 
  Public Shared Function SetConnectionState(ByVal connectionFolder As String, ByVal connectionName As String, ByVal enableVerb As String, ByVal disableVerb As String, ByVal enable As Boolean) As AdapterError
    Dim [error] As AdapterError = AdapterError.Success
 
    Dim networkConnectionsFolder As Folder = GetNetworkConnectionsFolder(connectionFolder)
    If networkConnectionsFolder Is Nothing Then
      [error] = AdapterError.ConnectionsFolderNotFound
    Else
      Dim networkConnection As FolderItem2 = GetNetworkConnection(networkConnectionsFolder, connectionName)
 
      If networkConnection Is Nothing Then
        [error] = AdapterError.ConnectionNotFound
      Else
        Dim verb As FolderItemVerb = Nothing
        If IsNetworkConnectionEnabled(networkConnection, enableVerb, disableVerb, verb) Then
          If enable Then
            [error] = AdapterError.ConnectionAlreadyOpen
          Else
            verb.DoIt()
            Thread.Sleep(2000)
          End If
        Else
          If Not enable Then
            [error] = AdapterError.ConnectionAlreadyClosed
          Else
            verb.DoIt()
            Thread.Sleep(2000)
          End If
        End If
      End If
    End If
 
    Return [error]
  End Function
 
  ''' <summary> 
  ''' Gets the Network Connections folder in the control panel. 
  ''' </summary> 
  Private Shared Function GetNetworkConnectionsFolder(ByVal folderName As String) As Folder
    Dim sh As New Shell()
 
    ' Get a reference to the Control panel. 
    Dim controlPanel As Folder = sh.[NameSpace](3)
 
    Dim items As FolderItems = controlPanel.Items()
    For Each item As FolderItem In items
      If item.Name = folderName Then
        Return TryCast(item.GetFolder, Folder)
      End If
    Next
 
    Return Nothing
  End Function
 
  ''' <summary> 
  ''' Gets the network connection with the specified name from the specified shell folder. 
  ''' </summary> 
  Private Shared Function GetNetworkConnection(ByVal networkConnectionsFolder As Folder, ByVal connectionName As String) As FolderItem2
    Dim items As FolderItems = networkConnectionsFolder.Items()
    For Each item As FolderItem2 In items
      If item.Name = connectionName Then
        Return item
      End If
    Next
 
    Return Nothing
  End Function
 
  ''' <summary> 
  ''' Gets whether or not the network connection is enabled and the command to enable/disable it. 
  ''' </summary> 
  Private Shared Function IsNetworkConnectionEnabled(ByVal networkConnection As FolderItem2, ByVal enableVerb As String, ByVal disableVerb As String, ByRef enableDisableVerb As FolderItemVerb) As Boolean
    enableDisableVerb = Nothing
 
    Dim verbs As FolderItemVerbs = networkConnection.Verbs()
    For Each verb As FolderItemVerb In verbs
      If verb.Name = enableVerb Then
        enableDisableVerb = verb
        Return False
      ElseIf verb.Name = disableVerb Then
        enableDisableVerb = verb
        Return True
      End If
    Next
    Return False
  End Function
 
End Class

Open in new window

0
 
awolarczukAuthor Commented:
Again mate thanks for your help so far, after look at the code i have found that this is not what i am looking for i am wanting basicly just to block port 80 and 8080 would will stop the internet and also the MSN from been used, i would like this as a little app in the in the tool bar near the clock that can be turn on the off with a password
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now