To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here
VBForums  

VB Wire News
MSDN Subscribers: Download the VS 2010 Release Candidate
MSDN Subscribers: Download the VS 2010 Release Candidate
Sell Your Code and Make Money?
Creating your own Tetris game using VB.NET
Article :: Improving Software Economics, Part 4 of 7: Top 10 Principles of Iterative Software Management



Go Back   VBForums > Visual Basic > Network Programming

Reply Post New Thread
 
Thread Tools Search this Thread Display Modes
Old Feb 24th, 2006, 01:38 AM   #1
tauhu82
Member
 
Join Date: Feb 06
Posts: 61
tauhu82 is an unknown quantity at this point (<10)
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..
tauhu82 is offline   Reply With Quote
Old Feb 24th, 2006, 11:10 AM   #2
the182guy
Frenzied Member
 
the182guy's Avatar
 
Join Date: Nov 05
Location: Cheshire, UK
Posts: 1,467
the182guy has a spectacular aura about (100+)the182guy has a spectacular aura about (100+)
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. Winsock1.GetData strBuffer
  3. If strBuffer = "[DISCONNECT]" & vbcrlf Then
  4.      'Call disconnect internet API here
  5. 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
  3.  
__________________
Chris

Codebank: Easy Javascript Form Validation (OOP)

If this post helped please rate it!
the182guy is offline   Reply With Quote
Old Feb 24th, 2006, 10:46 PM   #3
tauhu82
Member
 
Join Date: Feb 06
Posts: 61
tauhu82 is an unknown quantity at this point (<10)
Talking Thanks alot the182guy

Thank you so much. I will try it and tell you all what are the results. Have a nice day....
tauhu82 is offline   Reply With Quote
Old Mar 8th, 2006, 04:37 AM   #4
qhyzme
New Member
 
Join Date: Mar 06
Posts: 4
qhyzme is an unknown quantity at this point (<10)
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. Winsock1.GetData strBuffer
  3. If strBuffer = "[DISCONNECT]" & vbcrlf Then
  4.      'Call disconnect internet API here
  5. 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
  3.  
just wanna ask where i can see internet API.

thanks in advance.
qhyzme is offline   Reply With Quote
Old Mar 8th, 2006, 10:07 AM   #5
tauhu82
Member
 
Join Date: Feb 06
Posts: 61
tauhu82 is an unknown quantity at this point (<10)
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..
tauhu82 is offline   Reply With Quote
Old Mar 9th, 2006, 02:36 AM   #6
the182guy
Frenzied Member
 
the182guy's Avatar
 
Join Date: Nov 05
Location: Cheshire, UK
Posts: 1,467
the182guy has a spectacular aura about (100+)the182guy has a spectacular aura about (100+)
Re: Enable or disable internet connection of remote computers

This thread has the API's

http://www.vbforums.com/showthread.php?t=388647
__________________
Chris

Codebank: Easy Javascript Form Validation (OOP)

If this post helped please rate it!
the182guy is offline   Reply With Quote
Old Mar 12th, 2006, 11:41 AM   #7
tauhu82
Member
 
Join Date: Feb 06
Posts: 61
tauhu82 is an unknown quantity at this point (<10)
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
tauhu82 is offline   Reply With Quote
Old Mar 12th, 2006, 05:56 PM   #8
the182guy
Frenzied Member
 
the182guy's Avatar
 
Join Date: Nov 05
Location: Cheshire, UK
Posts: 1,467
the182guy has a spectacular aura about (100+)the182guy has a spectacular aura about (100+)
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

Codebank: Easy Javascript Form Validation (OOP)

If this post helped please rate it!
the182guy is offline   Reply With Quote
Old Mar 13th, 2006, 11:40 AM   #9
tauhu82
Member
 
Join Date: Feb 06
Posts: 61
tauhu82 is an unknown quantity at this point (<10)
Exclamation Need help with this coding!!!

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


VB Code:
  1. Server
  2. Private Sub Command1_Click()
  3. sckControlPanel.SendData "Connect#"
  4. End Sub
  5. Private Sub Command2_Click()
  6. sckControlPanel.SendData "Disconnect#"
  7. 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
tauhu82 is offline   Reply With Quote
Old Mar 13th, 2006, 11:44 AM   #10
the182guy
Frenzied Member
 
the182guy's Avatar
 
Join Date: Nov 05
Location: Cheshire, UK
Posts: 1,467
the182guy has a spectacular aura about (100+)the182guy has a spectacular aura about (100+)
Re: Enable or disable internet connection of remote computers

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

Codebank: Easy Javascript Form Validation (OOP)

If this post helped please rate it!
the182guy is offline   Reply With Quote
Old Mar 13th, 2006, 12:07 PM   #11
tauhu82
Member
 
Join Date: Feb 06
Posts: 61
tauhu82 is an unknown quantity at this point (<10)
Exclamation Re: Enable or disable internet connection of remote computers

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

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

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

It should have call for the disconnect to function. But nothing seem to be happening. I wonder why??
tauhu82 is offline   Reply With Quote
Old Mar 13th, 2006, 12:26 PM   #12
the182guy
Frenzied Member
 
the182guy's Avatar
 
Join Date: Nov 05
Location: Cheshire, UK
Posts: 1,467
the182guy has a spectacular aura about (100+)the182guy has a spectacular aura about (100+)
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

Codebank: Easy Javascript Form Validation (OOP)

If this post helped please rate it!
the182guy is offline   Reply With Quote
Old Mar 13th, 2006, 12:55 PM   #13
tauhu82
Member
 
Join Date: Feb 06
Posts: 61
tauhu82 is an unknown quantity at this point (<10)
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. Private Sub Form_Load()
  7.  Dim CancelConnection As Integer
  8.  Dim DriveLetter As String
  9.  Dim Force As Integer
  10.  
  11.     On Local Error GoTo CancelConnection_Err
  12.     CancelConnection = WNetCancelConnection(DriveLetter, Force)
  13.    
  14. CancelConnection_End:
  15.     Exit Sub
  16. CancelConnection_Err:
  17.     CancelConnection = Err
  18.     MsgBox Error$
  19.     Resume CancelConnection_End
  20.    
  21.    
  22. End Sub

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

Go Back   VBForums > Visual Basic > Network Programming


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 12:50 PM.




To view more projects, click here

Acceptable Use Policy


The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers

Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.