|
-
Jun 19th, 2012, 06:53 AM
#1
Thread Starter
Fanatic Member
[RESOLVED] connect / disconnect from the internet not dialup
hi
using api ,for win xp ,im not using dialup.
using this site http://allapi.mentalis.org/apilist/i.shtml .
how do i disconnect 1 pc on the internet ,ive read every thing in this forum
the api examples do not dont explain.
thanks
-
Jun 19th, 2012, 07:52 AM
#2
Re: connect / disconnect from the internet not dialup
see this link, may be useful for u.
-
Jun 19th, 2012, 08:13 AM
#3
Thread Starter
Fanatic Member
Re: connect / disconnect from the internet not dialup
rasapi32.dll is dial up but im still looking
-
Jun 19th, 2012, 10:06 AM
#4
Thread Starter
Fanatic Member
Re: connect / disconnect from the internet not dialup
toggle internet connection
hey this is writen in vbs
Code:
set objShell=CreateObject("shell.application")
' Toggle NIC on or off
Option Explicit
Dim objCP, objEnable, objDisable, colNetwork
Dim clsConn, clsLANConn, clsVerb
Dim strNetConn, strConn, strEnable, strDisable
Dim bEnabled, bDisabled
Const NETWORK_CONNECTIONS = &H31&
strConn = "Local Area Connection"
'strEnable = "En&able"
strEnable = "&Aktivieren"
'strDisable = "Disa&ble"
strDisable = "&Deaktivieren"
Set colNetwork = Nothing
Set colNetwork = objShell.Namespace(NETWORK_CONNECTIONS) ' Network Connections (independent of country/language)
If colNetwork is Nothing Then
WScript.Echo "Network folder not found"
WScript.Quit
End If
Set clsLANConn = Nothing
For Each clsConn in colNetwork.Items
' In case the LAN is named “connection 2”, etc.
If Instr(LCase(clsConn.name),LCase(strConn)) Then
Set clsLANConn = clsConn
Exit For
End If
Next
' WScript.Echo clsLANConn
If clsLANConn is Nothing Then
WScript.Echo "Network Connection not found"
WScript.Quit
End If
bEnabled = True
Set objEnable = Nothing
Set objDisable = Nothing
For Each clsVerb in clsLANConn.verbs
' WScript.Echo clsVerb.name
If clsVerb.name = strEnable Then
Set objEnable = clsVerb
bEnabled = False
End If
If clsVerb.name = strDisable Then
Set objDisable = clsVerb
End If
Next
If bEnabled Then
objDisable.DoIt
WScript.Echo clsLANConn & " deaktiviert"
Else
objEnable.DoIt
WScript.Echo clsLANConn & " aktiviert"
End If
'Give the connection time to stop/start
WScript.Sleep 1000
this is in vb.net i think
can vb6 do this??
thanks
Code:
Public Class ToggleNetworkConnection
#Region "Public Methods"
Public Shared Sub ToggleWirelessConnection()
For Each verb As Shell32.FolderItemVerb In WirelessConnectionFolderItem.Verbs
If verb.Name = "En&able" OrElse verb.Name = "Disa&ble" Then
verb.DoIt()
Exit For
End If
Next
Threading.Thread.Sleep(1000)
End Sub
Public Shared Sub ToggleLocalAreaConnection()
For Each verb As Shell32.FolderItemVerb In LocalAreaConnectionFolderItem.Verbs
If verb.Name = "En&able" OrElse verb.Name = "Disa&ble" Then
verb.DoIt()
Exit For
End If
Next
Threading.Thread.Sleep(1000)
End Sub
#End Region
#Region "Properties"
Private Shared ReadOnly Property ControlPanelFolder() As Shell32.Folder
Get
Dim shell As New Shell32.Shell()
Return shell.NameSpace(3)
End Get
End Property
Private Shared ReadOnly Property NetworkFolder() As Shell32.Folder
Get
Dim retVal As Shell32.Folder = Nothing
For Each fi As Shell32.FolderItem In ControlPanelFolder.Items
If fi.Name = "Network Connections" Then
retVal = fi.GetFolder()
End If
Next
If retVal Is Nothing Then
Throw New NetworkConnectionsFolderNotFoundException()
Else
Return retVal
End If
End Get
End Property
Private Shared ReadOnly Property LocalAreaConnectionFolderItem() As Shell32.FolderItem
Get
Dim retVal As Shell32.FolderItem = Nothing
For Each folderItem As Shell32.FolderItem In NetworkFolder.Items
Console.WriteLine(folderItem.Name)
If InStr(folderItem.Name.ToLower(), "Local Area Connection".ToLower()) Then
retVal = folderItem
Exit For
End If
Next
If retVal Is Nothing Then
Throw New LocalAreaConnectionFolderItemNotFoundException()
Else
Return retVal
End If
End Get
End Property
Private Shared ReadOnly Property WirelessConnectionFolderItem() As Shell32.FolderItem
Get
Dim retVal As Shell32.FolderItem = Nothing
For Each folderItem As Shell32.FolderItem In NetworkFolder.Items
Console.WriteLine(folderItem.Name)
If InStr(folderItem.Name.ToLower(), _
"Wireless Network Connection".ToLower()) Then
retVal = folderItem
Exit For
End If
Next
If retVal Is Nothing Then
Throw New WirelessConnectionFolderItemNotFoundException()
Else
Return retVal
End If
End Get
End Property
#End Region
#Region "Custom Exceptions"
Public Class NetworkConnectionsFolderNotFoundException
Inherits Exception
Public Overrides ReadOnly Property Message() As String
Get
Return "The Network Connections Folder Could Not Be Found!"
End Get
End Property
End Class
Public Class LocalAreaConnectionFolderItemNotFoundException
Inherits Exception
Public Overrides ReadOnly Property Message() As String
Get
Return "The Local Area Connection Folder Could Not Be Found!"
End Get
End Property
End Class
Public Class WirelessConnectionFolderItemNotFoundException
Inherits Exception
Public Overrides ReadOnly Property Message() As String
Get
Return "The Wireless Connection Folder Could Not Be Found!"
End Get
End Property
End Class
#End Region
End Class
-
Jun 19th, 2012, 10:23 AM
#5
Re: connect / disconnect from the internet not dialup
It appears that the code you are looking at would disable your network connection. I suppose that would be ok if you are the only pc on the network or do not need to access any other PC or device on the network.
If you are using a router it may be possible to disconnect your internet connection from the network by talking to the router. I do not know how exactly as I have never looked into it but most routers have a web interface that allows you to start/stop the internet connection, some may even provide an APi to do so.
-
Jun 19th, 2012, 01:08 PM
#6
Re: connect / disconnect from the internet not dialup
 Originally Posted by DataMiser
It appears that the code you are looking at would disable your network connection. I suppose that would be ok if you are the only pc on the network or do not need to access any other PC or device on the network.
If you are using a router it may be possible to disconnect your internet connection from the network by talking to the router. I do not know how exactly as I have never looked into it but most routers have a web interface that allows you to start/stop the internet connection, some may even provide an APi to do so.
That is what my router can do. I can talk to my router via code and tell it to do certain things that you would normally do by using the interface and clicking on buttons. You need to understand your router and how to set up a direct link to it and know what messages etc to send to it. Be careful doing this because if you screw up you might wish you hadn't fiddled with it if you don't know how to rest it back to where it was
Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.
-
Jun 19th, 2012, 01:19 PM
#7
Thread Starter
Fanatic Member
Re: connect / disconnect from the internet not dialup
strConn = "Local Area Connection"
is in network connections,under start,control panel
i thought it was only the computer i would run the program on,,thanks
Last edited by flyhigh; Jun 19th, 2012 at 01:24 PM.
-
Jun 19th, 2012, 01:24 PM
#8
Re: connect / disconnect from the internet not dialup
If you disconnect the computer from the network then it will be only that computer but it will deny all network access in or out not just the internet. If you shut down the internet at the router then it will shut down the internet for the whole network not just the pc you are using.
-
Jun 19th, 2012, 02:25 PM
#9
Re: connect / disconnect from the internet not dialup
 Originally Posted by DataMiser
If you disconnect the computer from the network then it will be only that computer but it will deny all network access in or out not just the internet. If you shut down the internet at the router then it will shut down the internet for the whole network not just the pc you are using.
Exactly, but instead you just disconnect a particular PC which has it's own internal IP address. The other computers on that network will not be affected
Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.
-
Jun 19th, 2012, 04:27 PM
#10
Thread Starter
Fanatic Member
Re: connect / disconnect from the internet not dialup
i got it to work in vb6
thanks all
Code:
Option Explicit
Dim LANEnable As Boolean
Dim Count1 As Byte
Dim EnableVerb As String
Dim DisableVerb As String
Dim ConnectionName As String
Dim EnableVerbItem As Shell32.FolderItemVerb
Dim DisableVerbItem As Shell32.FolderItemVerb
Dim Verb As Shell32.FolderItemVerb
Dim ShellApp As Shell32.Shell
Dim ControlPanel As Shell32.Folder
Dim FolderItem As Shell32.FolderItem
Dim NetworkFolder As Shell32.Folder
Dim LANConnection As Shell32.FolderItem
'put 2 comman buttons on form
'goto >>project>>references>>scrool down to microsoft shell controls and automation>>select ok
Private Sub Command1_Click()
ConnectionName = "Local Area Connection"
Set ShellApp = New Shell32.Shell
DisableVerb = "Disa&ble"
EnableVerb = "En&able"
Set ControlPanel = ShellApp.NameSpace(ssfCONTROLS)
' Loop through the items in the control panel and obtain the Network Connections folder
For Each FolderItem In ControlPanel.Items()
'MsgBox FolderItem.Name
If InStr(1, FolderItem.Name, "Network", vbTextCompare) <> 0 Then
' When found - exit the loop
Set NetworkFolder = FolderItem.GetFolder
Exit For
End If
Next
If NetworkFolder Is Nothing Then
Exit Sub
End If
' Obtain the appropriate connection record
For Each FolderItem In NetworkFolder.Items()
'MsgBox FolderItem.Name
If InStr(1, FolderItem.Name, ConnectionName, vbTextCompare) <> 0 Then
' When found - exit the loop
Set LANConnection = FolderItem
Exit For
End If
Next
If LANConnection Is Nothing Then
Exit Sub
End If
' Run through all available options and obtain the appropriate action
For Each Verb In LANConnection.Verbs
If Verb.Name = EnableVerb Then
Set EnableVerbItem = Verb
End If
If Verb.Name = DisableVerb Then
Set DisableVerbItem = Verb
End If
Next
' Perform the enable / disable
If LANEnable Then
If EnableVerbItem Is Nothing Then Exit Sub
EnableVerbItem.DoIt
Else
If DisableVerbItem Is Nothing Then Exit Sub
DisableVerbItem.DoIt
End If
End Sub
Private Sub Command2_Click()
ConnectionName = "Local Area Connection"
Set ShellApp = New Shell32.Shell
DisableVerb = "Disa&ble"
EnableVerb = "En&able"
Set ControlPanel = ShellApp.NameSpace(ssfCONTROLS)
' Loop through the items in the control panel and obtain the Network Connections folder
For Each FolderItem In ControlPanel.Items()
'MsgBox FolderItem.Name
If InStr(1, FolderItem.Name, "Network", vbTextCompare) <> 0 Then
' When found - exit the loop
Set NetworkFolder = FolderItem.GetFolder
Exit For
End If
Next
If NetworkFolder Is Nothing Then
Exit Sub
End If
' Obtain the appropriate connection record
For Each FolderItem In NetworkFolder.Items()
'MsgBox FolderItem.Name
If InStr(1, FolderItem.Name, ConnectionName, vbTextCompare) <> 0 Then
' When found - exit the loop
Set LANConnection = FolderItem
Exit For
End If
Next
If LANConnection Is Nothing Then
Exit Sub
End If
' Run through all available options and obtain the appropriate action
For Each Verb In LANConnection.Verbs
If Verb.Name = EnableVerb Then
Set EnableVerbItem = Verb
End If
If Verb.Name = DisableVerb Then
Set DisableVerbItem = Verb
End If
Next
' Perform the enable / disable
If LANEnable = False Then
If EnableVerbItem Is Nothing Then Exit Sub
EnableVerbItem.DoIt
End If
End Sub
-
Jun 19th, 2012, 04:37 PM
#11
Re: [RESOLVED] connect / disconnect from the internet not dialup
Great! Now if that code really works I know how to do it the easy way. Thanks for solving your own problem, that really helped me too.
Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.
-
Jun 19th, 2012, 04:44 PM
#12
Thread Starter
Fanatic Member
Re: [RESOLVED] connect / disconnect from the internet not dialup
im sorry ,its what i needed it to do.
but if there a better way ,maybe safer than that ,please help
thanks all
-
Jun 19th, 2012, 04:49 PM
#13
Re: [RESOLVED] connect / disconnect from the internet not dialup
I don't know if that code is the best way or not but it is certainly better than messing around with the modem/router.
Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|