Link to home
Start Free TrialLog in
Avatar of crystalsoft
crystalsoft

asked on

How to close Selected folder From Server to Client

Hello Experts
Happy New Year
I have asked a Following Question.
(How to close Selected folder : 12/30/09 08:47 PM, ID: 25010417)

and i got answer its working on my project.
But now my requirement is Closing folder from server to Client.

Admin can close clients folder. How can i do that using vb6.0 code

operating system is windows xp prof

Thanks in advance



Avatar of nffvrxqgrcfqvvc
nffvrxqgrcfqvvc

Hi, You could use the Winsock Control
http://msdn.microsoft.com/en-us/library/aa733709(VS.60).aspx

The server would have the code to close windows and the client would send the message to the server to do an action. If you install the server on each computer than you can broadcast to all at once using UDP protocal on the local network. However if you want to work outside the local network you will have to use TCP protocal.
Avatar of crystalsoft

ASKER

Thanks for reply

I tried the code from suggested above site and Run

but its giving me error
"Run Time Error 10014" Invalid Argument

Highlighted on following line when DEBUG

Private Sub txtSend_Change()
    ' Send text as soon as it's typed.
    udpPeerA.SendData txtSend.Text
End Sub

I'll simplify the example for you it might help. The server would be what you run/install on each computer on the local network. The client is how you control the server or the application that will send messages to all the servers. If you use the broadcast address it should send to all computers on the network.

The server must be running to broadcast the message using the client.

You will use two projects in this case one for the client and the other that acts as the server.

Client:
Add 1 Command Button
Add 1 Winsock Control

Server:
Add 1 Winsock Control

'//
'// CLIENT
'//

Option Explicit

'client

Private Sub Command1_Click()

  Winsock1.SendData "closewindows"

End Sub

Private Sub Form_Load()

    With Winsock1
        .RemoteHost = "255.255.255.255"   ' Broadcast IP
        .RemotePort = 2001                ' Port to connect to.
        .Bind 2002                        ' Bind to the local port.
    End With

End Sub




'//
'// SERVER
'//

Option Explicit

'server
Private Sub Form_Load()

    Winsock1.RemotePort = 2002
    Winsock1.RemoteHost = "255.255.255.255"
    Winsock1.Bind 2001
    
End Sub

Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
  Dim strData As String
  Winsock1.GetData strData
  Select Case strData
    Case "closewindows"
    '// Run code to close a window on PC.
    MsgBox "HIT TEST", vbSystemModal
  End Select
End Sub

Open in new window


when i am running on my local machine, its giving me error

Run Time error '40006'
"Wrong protocol or connection state for the requested transaction or request"

on this line i added my local IP address on both project

 Winsock1.RemoteHost = "255.255.255.255"
Have you changed the protocal to use UDP? You can do it using code or if you select the control you can change it in the properties page.
winsock1.Protocol =sckUDPProtocol

Open in new window

If you use a broadcast address ex. 255.255.255.255 then it will send the message to all computers running the server. If you use a local ip address only that computer will get message.

It's possible broadcast address could be different for each network but the most common of them is 255.255.255.255, 192.168.1.255 etc.

Here is a quick site that gives you the broadcast address that you will need for the network you use
http://www.tech-faq.com/calculate-broadcast-address.shtml
Hi egl1044

Sorry for late replying
Now i am not getting any error.

But also nothing happened.

Coding i am using according to your suggestion

'//
'// SERVER
'//

Option Explicit

'server
Private Sub Form_Load()

    Winsock1.RemotePort = 2002
    Winsock1.RemoteHost = "192.168.1.255"
    Winsock1.Bind 2001
   
End Sub

Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
  Dim strData As String
  Winsock1.GetData strData
  Select Case strData
    Case "closewindows"
    '// Run code to close a window on PC.
    MsgBox "HIT TEST", vbSystemModal
  End Select
End Sub



'//
'// CLIENT
'//

Option Explicit

'client

Private Sub Command1_Click()

  Winsock1.SendData "closewindows"

End Sub

Private Sub Form_Load()

    With Winsock1
        .RemoteHost = "192.168.1.255"       ' Broadcast IP
        .RemotePort = 2001                ' Port to connect to.
        .Bind 2002                        ' Bind to the local port.
    End With

End Sub

both server and client coding in different different project
(2-Project) one is for client and one is for server

Did you run both projects and do you have a firewall installed that might have blocked the port?

Make sure the broadcast address is correct. I have tested and it displays a messagebox on every computer on my network that I ran the server on.
yup i run both project on single pc.
and yes You are absolutely right.

firewall is blocking all activity.

i unblocked it and now its giving me error

Run Time Error "10022"
Socket not bound, Invalid address or listen is not invoked prior to accept.

on debug click Highlighted on this line
Winsock1.SendData "closewindows"
I'm not sure the problem working fine on my end. The broadcast address might be wrong or the firewall is still blocking access.
yeh firewall was blocking access.
when i am disabling whole firewall then only sending msg to the clinet.

ok now whats next buddy?

If you're working in a trusted environment the "application" firewall not the router firewall for UDP there is usually an option to allow local network to the trusted filter. You should also be able to allow specific ports,ip addresses or applications(your server executable) access without the firewall application blocking the port.

The example sends the message "closewindows" you could send the title of the window that you want to close from the client like this "closewindows:notepad" from your server use Split() specify ":" as delimeter. You will end up with an array data(0) data(1) the data(0) is the command(closewindows). The data(1) is the extra string(notepad) you can then pass data(1) to a routine in the server.

Sorry egl1044: for delay
I was busy with another projects.

Program running on remote pc. This Program is displaying applications lists which is running on that machine.
And every after 10 seconds Program will refreshing automatically.
 
Now how can i get that lists to the server. so i can see what is happening and if i will see there some exceptionable site or application is open then i can close from my server.

if you want code till i am getting local application list i can give you here

Thanks.
ASKER CERTIFIED SOLUTION
Avatar of nffvrxqgrcfqvvc
nffvrxqgrcfqvvc

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial