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..
Printable View
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..
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:
In the server command button which DC's the clientVB Code:
Dim strBuffer as String Winsock1.GetData strBuffer If strBuffer = "[DISCONNECT]" & vbcrlf Then 'Call disconnect internet API here End if
VB Code:
Winsock1(2).SendData "[DISCONNECT]" & vbCrLf 'This will tell client 2 to d/c
Thank you so much. I will try it and tell you all what are the results. Have a nice day....
just wanna ask where i can see internet API.Quote:
Originally Posted by the182guy
thanks in advance.
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..
This thread has the API's
http://www.vbforums.com/showthread.php?t=388647
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
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
VB Code:
Client Case "Connect" AddConnection Case "Disconnect" CancelConnection Module Public Declare Function WNetAddConnection Lib "mpr.dll" Alias "WNetAddConnectionA" (ByVal lpszNetPath As String, ByVal lpszPassword As String, ByVal lpszLocalName As String) As Long Public Declare Function WNetCancelConnection Lib "mpr.dll" Alias "WNetCancelConnectionA" (ByVal lpszName As String, ByVal bForce As Long) As Long Public Const WN_SUCCESS = 0 ' The function was successful. Public Const WN_NET_ERROR = 2 ' An error occurred on the network. Public Const WN_BAD_PASSWORD = 6 ' The password was invalid. Public Sub AddConnection() Dim AddConnection As Integer Dim MyShareName As String Dim MyPWD As String Dim UseLetter As String On Local Error GoTo AddConnection_Err AddConnection = WNetAddConnection(MyShareName, MyPWD, UseLetter) AddConnection_End: Exit Sub AddConnection_Err: AddConnection = Err MsgBox Error$ Resume AddConnection_End End Sub Public Sub CancelConnection() Dim CancelConnection As Integer Dim DriveLetter As String Dim Force As Integer On Local Error GoTo CancelConnection_Err CancelConnection = WNetCancelConnection(DriveLetter, Force) CancelConnection_End: Exit Sub CancelConnection_Err: CancelConnection = Err MsgBox Error$ Resume CancelConnection_End End Sub
VB Code:
Server Private Sub Command1_Click() sckControlPanel.SendData "Connect#" End Sub Private Sub Command2_Click() sckControlPanel.SendData "Disconnect#" 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
do you have any code so that the client can receive the data?
VB Code:
Client Private Sub sckControlPanel_DataArrival(ByVal bytesTotal As Long) Dim Command As String, txtData As String Dim Position As Integer On Error Resume Next sckControlPanel.GetData txtData Position = InStr(1, txtData, "#") Command = Left(txtData, Position - 1) txtData = Mid(txtData, Position + 1) Select Case Command Case "ScreenSaver" RunScreenSaver Case "CDDoor" If txtData = "Open" Then OpenCDDoor Else CloseCDDoor End If Case "LockSystem" SystemParametersInfo SPI_SCREENSAVERRUNNING, _ 1&, Null, SPIF_UPDATEINIFILE LockForm.Show Case "UnLockSystem" Unload LockForm UnlockForm.Show Case "Logoff" ExitWindowsEx (EWX_LOGOFF Or EWX_FORCE), &HFFFF Case "Reboot" AdjustToken ExitWindowsEx (EWX_SHUTDOWN Or EWX_FORCE Or EWX_REBOOT), &HFFFF Case "Shutdown" AdjustToken ExitWindowsEx (EWX_SHUTDOWN Or EWX_FORCE), &HFFFF Case "GetUserName" txtData = GetUser() sckControlPanel.SendData "GetUserName#" & txtData Case "GetTickCount" txtData = GetLoginTime sckControlPanel.SendData "GetTickCount#" & txtData Case "SystemInfo" txtData = "SystemInfo#" & SystemInfo() sckControlPanel.SendData txtData Case "Connect" AddConnection Case "Disconnect" CancelConnection Case "Message" MsgBox txtData, vbExclamation, "Windows Message" Case "Date&Time" Case "Mouse" End Select End Sub
I put this part at the client side. so when i execude this
VB Code:
Server Private Sub Command1_Click() sckControlPanel.SendData "Connect#" End Sub Private Sub Command2_Click() sckControlPanel.SendData "Disconnect#" End Sub
It should have call for the disconnect to function. But nothing seem to be happening. I wonder why??
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
I have tried with the msgbox and the connection part is ok so i have also tried with this
VB Code:
Private Declare Function WNetAddConnection Lib "mpr.dll" Alias "WNetAddConnectionA" (ByVal lpszNetPath As String, ByVal lpszPassword As String, ByVal lpszLocalName As String) As Long Private Declare Function WNetCancelConnection Lib "mpr.dll" Alias "WNetCancelConnectionA" (ByVal lpszName As String, ByVal bForce As Long) As Long Const WN_SUCCESS = 0 ' The function was successful. Const WN_NET_ERROR = 2 ' An error occurred on the network. Const WN_BAD_PASSWORD = 6 ' The password was invalid. Private Sub Form_Load() Dim CancelConnection As Integer Dim DriveLetter As String Dim Force As Integer On Local Error GoTo CancelConnection_Err CancelConnection = WNetCancelConnection(DriveLetter, Force) CancelConnection_End: Exit Sub CancelConnection_Err: CancelConnection = Err MsgBox Error$ Resume CancelConnection_End End Sub
On a single form and when i excecute it also nothing is happening. Can someone tell me why???