Can anyone please help me on this?

The server is supposed to see which computers are online and which are not.
if the workstation are not online the computer should not be seen on the server's list but if it open again the computer name should appear on the list.

This is the codes I used

Private Sub btnShutdown_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnShutdown.Click
On Error Resume Next
If MessageBox.Show("Are you sure you wish to shutdown " & Computer & "?", "Confirm shutdown", _
MessageBoxButtons.YesNo, MessageBoxIcon.Question) = System.Windows.Forms.DialogResult.Yes Then
strOperation = "SHUTDOWN"
compIPaddress = ""
compIPaddress = System.Net.Dns.GetHostByName(Computer).AddressList(0).ToString()
If Trim(compIPaddress) = "" Then
MsgBox("Please select a computer!!!", MsgBoxStyle.Information, "Computer???")
Else
trSendMessage = New Thread(AddressOf SendMessage)
trSendMessage.Start()
MessageBox.Show("Client " & Computer & " has been shutdown.")
TVComputers.Nodes.Remove(TVComputers.SelectedNode)
End If
End If
End Sub

the shutdown button is working, the problem is, when i open again the computer that is being shutdown on the workstation, it is not appearing on the server's list. what's wrong with the code and what should I do?

Thanks a lot in advance.

the shutdown button is working, the problem is, when i open again the computer that is being shutdown on the workstation, it is not appearing on the server's list.

Your code shuts down a computer, but how did you get NetBIOS/DNS names in the first place? I assume TVComputers holds those names. Post that code instead.

Why do you start a new thread ( trSendMessage = New Thread(AddressOf SendMessage) ) for the shutdown? AFAIK if you send a remote shutdown, it is asynchronous by nature i.e. you don't get any return code if the remote shutdown failed. On Error Resume Next is extremely bad way to handle exceptions and/or errors. In your snippet, compIPaddress = System.Net.Dns.GetHostByName(Computer).AddressList(0).ToString() is almost only place which could fail. I suggest using Try...Catch block instead if the name resolution fails.

HTH

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.