Results 1 to 13 of 13

Thread: Enable or disable internet connection of remote computers

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2006
    Posts
    61

    Exclamation Enable or disable internet connection of remote computers

    Halo i'm looking for ways to enable or disable internet connection of remote computers, like everythings are controlled by the server computer. Can anyone give me some advise on this matter... A sampel would be nice.. Thanks alot..

  2. #2
    Frenzied Member the182guy's Avatar
    Join Date
    Nov 2005
    Location
    Cheshire, UK
    Posts
    1,473

    Re: Enable or disable internet connection of remote computers

    When you want to disconnect the internet of the client you can do it by having your server send some data which tells it to d/c, when the clients receives this, it calls the disconnect internet API which can be found on this forum if you search.

    client data arrival sub:
    VB Code:
    1. Dim strBuffer as String
    2.  
    3. Winsock1.GetData strBuffer
    4.  
    5. If strBuffer = "[DISCONNECT]" & vbcrlf Then
    6.      'Call disconnect internet API here
    7. End if
    In the server command button which DC's the client
    VB Code:
    1. Winsock1(2).SendData "[DISCONNECT]" & vbCrLf
    2. 'This will tell client 2 to d/c
    Chris

  3. #3

    Thread Starter
    Member
    Join Date
    Feb 2006
    Posts
    61

    Talking Thanks alot the182guy

    Thank you so much. I will try it and tell you all what are the results. Have a nice day....

  4. #4
    New Member
    Join Date
    Mar 2006
    Posts
    4

    Re: Enable or disable internet connection of remote computers

    Quote Originally Posted by the182guy
    When you want to disconnect the internet of the client

    client data arrival sub:
    VB Code:
    1. Dim strBuffer as String
    2.  
    3. Winsock1.GetData strBuffer
    4.  
    5. If strBuffer = "[DISCONNECT]" & vbcrlf Then
    6.      'Call disconnect internet API here
    7. End if
    In the server command button which DC's the client
    VB Code:
    1. Winsock1(2).SendData "[DISCONNECT]" & vbCrLf
    2. 'This will tell client 2 to d/c
    just wanna ask where i can see internet API.

    thanks in advance.

  5. #5

    Thread Starter
    Member
    Join Date
    Feb 2006
    Posts
    61

    Talking Where to find disconnect internet API ??

    I have tried to find the disconnect internet API but i can't seem to find it anywhere. Can someone please show us where to find it.

    Thanks alot..

  6. #6
    Frenzied Member the182guy's Avatar
    Join Date
    Nov 2005
    Location
    Cheshire, UK
    Posts
    1,473

    Re: Enable or disable internet connection of remote computers

    Chris

  7. #7

    Thread Starter
    Member
    Join Date
    Feb 2006
    Posts
    61

    Talking Re: Enable or disable internet connection of remote computers

    Hai the182guy,

    Thanks for your API site. But i still have one small question. Can the coding work if the computer is connected to the internet though LAN. We are using broadband with router and switch to connect to each of the computers to the internet.

    Thanks alot in advanced

  8. #8
    Frenzied Member the182guy's Avatar
    Join Date
    Nov 2005
    Location
    Cheshire, UK
    Posts
    1,473

    Re: Enable or disable internet connection of remote computers

    if your using a router, you can d/c the network conection using the WNNetCancel API, here it is:

    http://www.mentalis.org/apilist/WNet...nnection.shtml
    Chris

  9. #9

    Thread Starter
    Member
    Join Date
    Feb 2006
    Posts
    61

    Exclamation Need help with this coding!!!

    VB Code:
    1. Client
    2.  
    3.         Case "Connect"
    4.              AddConnection
    5.         Case "Disconnect"
    6.              CancelConnection
    7.  
    8. Module
    9. Public Declare Function WNetAddConnection Lib "mpr.dll" Alias "WNetAddConnectionA" (ByVal lpszNetPath As String, ByVal lpszPassword As String, ByVal lpszLocalName As String) As Long
    10. Public Declare Function WNetCancelConnection Lib "mpr.dll" Alias "WNetCancelConnectionA" (ByVal lpszName As String, ByVal bForce As Long) As Long
    11. Public Const WN_SUCCESS = 0 ' The function was successful.
    12. Public Const WN_NET_ERROR = 2 ' An error occurred on the network.
    13. Public Const WN_BAD_PASSWORD = 6 ' The password was invalid.
    14.  
    15. Public Sub AddConnection()
    16.  
    17.  Dim AddConnection As Integer
    18.  Dim MyShareName As String
    19.  Dim MyPWD As String
    20.  Dim UseLetter As String
    21.  
    22.     On Local Error GoTo AddConnection_Err
    23.     AddConnection = WNetAddConnection(MyShareName, MyPWD, UseLetter)
    24. AddConnection_End:
    25.     Exit Sub
    26. AddConnection_Err:
    27.     AddConnection = Err
    28.     MsgBox Error$
    29.     Resume AddConnection_End
    30. End Sub
    31.  
    32. Public Sub CancelConnection()
    33.  Dim CancelConnection As Integer
    34.  Dim DriveLetter As String
    35.  Dim Force As Integer
    36.  
    37.     On Local Error GoTo CancelConnection_Err
    38.     CancelConnection = WNetCancelConnection(DriveLetter, Force)
    39. CancelConnection_End:
    40.     Exit Sub
    41. CancelConnection_Err:
    42.     CancelConnection = Err
    43.     MsgBox Error$
    44.     Resume CancelConnection_End
    45. End Sub


    VB Code:
    1. Server
    2.  
    3. Private Sub Command1_Click()
    4. sckControlPanel.SendData "Connect#"
    5. End Sub
    6.  
    7. Private Sub Command2_Click()
    8. sckControlPanel.SendData "Disconnect#"
    9. End Sub

    PS:sckControlPanel = Winsock

    Guys the above are the two of the coding which i obtain from http://www.mentalis.org/apilist/WNet...nnection.shtml

    The first part is for the client side and the second one is for the server side. Now i wonder what did i do wrong because when i execute the disconnect command from the server side to the client, nothing is happening. Can somebody tell me what is wrong please....

    Thanks alot in advanced

  10. #10
    Frenzied Member the182guy's Avatar
    Join Date
    Nov 2005
    Location
    Cheshire, UK
    Posts
    1,473

    Re: Enable or disable internet connection of remote computers

    do you have any code so that the client can receive the data?
    Chris

  11. #11

    Thread Starter
    Member
    Join Date
    Feb 2006
    Posts
    61

    Exclamation Re: Enable or disable internet connection of remote computers

    VB Code:
    1. Client
    2.  
    3. Private Sub sckControlPanel_DataArrival(ByVal bytesTotal As Long)
    4. Dim Command As String, txtData As String
    5. Dim Position As Integer
    6.    
    7. On Error Resume Next
    8.     sckControlPanel.GetData txtData
    9.    
    10.     Position = InStr(1, txtData, "#")
    11.     Command = Left(txtData, Position - 1)
    12.     txtData = Mid(txtData, Position + 1)
    13.    
    14.     Select Case Command
    15.            
    16.         Case "ScreenSaver"
    17.             RunScreenSaver
    18.         Case "CDDoor"
    19.             If txtData = "Open" Then
    20.                 OpenCDDoor
    21.             Else
    22.                 CloseCDDoor
    23.             End If
    24.         Case "LockSystem"
    25.             SystemParametersInfo SPI_SCREENSAVERRUNNING, _
    26.             1&, Null, SPIF_UPDATEINIFILE
    27.             LockForm.Show
    28.         Case "UnLockSystem"
    29.              Unload LockForm
    30.              UnlockForm.Show
    31.         Case "Logoff"
    32.             ExitWindowsEx (EWX_LOGOFF Or EWX_FORCE), &HFFFF
    33.         Case "Reboot"
    34.             AdjustToken
    35.             ExitWindowsEx (EWX_SHUTDOWN Or EWX_FORCE Or EWX_REBOOT), &HFFFF
    36.         Case "Shutdown"
    37.             AdjustToken
    38.             ExitWindowsEx (EWX_SHUTDOWN Or EWX_FORCE), &HFFFF
    39.         Case "GetUserName"
    40.             txtData = GetUser()
    41.             sckControlPanel.SendData "GetUserName#" & txtData
    42.         Case "GetTickCount"
    43.             txtData = GetLoginTime
    44.             sckControlPanel.SendData "GetTickCount#" & txtData
    45.         Case "SystemInfo"
    46.             txtData = "SystemInfo#" & SystemInfo()
    47.             sckControlPanel.SendData txtData
    48.         Case "Connect"
    49.              AddConnection
    50.         Case "Disconnect"
    51.              CancelConnection
    52.         Case "Message"
    53.             MsgBox txtData, vbExclamation, "Windows Message"
    54.         Case "Date&Time"
    55.         Case "Mouse"
    56.     End Select
    57. End Sub

    I put this part at the client side. so when i execude this

    VB Code:
    1. Server
    2.  
    3. Private Sub Command1_Click()
    4. sckControlPanel.SendData "Connect#"
    5. End Sub
    6.  
    7. Private Sub Command2_Click()
    8. sckControlPanel.SendData "Disconnect#"
    9. End Sub

    It should have call for the disconnect to function. But nothing seem to be happening. I wonder why??

  12. #12
    Frenzied Member the182guy's Avatar
    Join Date
    Nov 2005
    Location
    Cheshire, UK
    Posts
    1,473

    Re: Enable or disable internet connection of remote computers

    in the Case "Disconnect" part put a msgbox and try it, this will tell you if its a problem with the connection/data arrival or a problem with the CancelConnectionAPI

    also make s small app that just uses the CancelConnection API and try it, to see if the API actually works
    Chris

  13. #13

    Thread Starter
    Member
    Join Date
    Feb 2006
    Posts
    61

    Exclamation Re: Enable or disable internet connection of remote computers

    I have tried with the msgbox and the connection part is ok so i have also tried with this

    VB Code:
    1. Private Declare Function WNetAddConnection Lib "mpr.dll" Alias "WNetAddConnectionA" (ByVal lpszNetPath As String, ByVal lpszPassword As String, ByVal lpszLocalName As String) As Long
    2. Private Declare Function WNetCancelConnection Lib "mpr.dll" Alias "WNetCancelConnectionA" (ByVal lpszName As String, ByVal bForce As Long) As Long
    3. Const WN_SUCCESS = 0 ' The function was successful.
    4. Const WN_NET_ERROR = 2 ' An error occurred on the network.
    5. Const WN_BAD_PASSWORD = 6 ' The password was invalid.
    6.  
    7. Private Sub Form_Load()
    8.  Dim CancelConnection As Integer
    9.  Dim DriveLetter As String
    10.  Dim Force As Integer
    11.  
    12.     On Local Error GoTo CancelConnection_Err
    13.     CancelConnection = WNetCancelConnection(DriveLetter, Force)
    14.    
    15. CancelConnection_End:
    16.     Exit Sub
    17. CancelConnection_Err:
    18.     CancelConnection = Err
    19.     MsgBox Error$
    20.     Resume CancelConnection_End
    21.    
    22.    
    23. End Sub

    On a single form and when i excecute it also nothing is happening. Can someone tell me why???

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width