Introduction
This application can be used to shutdown, reboot, and logoff remote PCs. Client application that is 'remoteClientX
' must be installed on client PCs and 'ServerX
' is used to give commands like shutdown, reboot and logoff.
Listen State Module of remoteClientX
Sub ListenToServer()
Try
Dim LISTENING As Boolean
Dim localhostAddress As IPAddress = IPAddress.Parse(ipAddress.ToString)
Dim port As Integer = 63000
Dim tcpList As New TcpListener(localhostAddress, port)
Try
tcpList.Start()
LISTENING = True
Do While LISTENING
Do While tcpList.Pending = False And LISTENING = True
Thread.Sleep(10)
Loop
If Not LISTENING Then Exit Do
Dim tcpCli As TcpClient = tcpList.AcceptTcpClient()
Dim ns As NetworkStream = tcpCli.GetStream
Dim sr As New StreamReader(ns)
Dim receivedData As String = sr.ReadLine()
If receivedData = "###SHUTDOWN###" Then
trShutdown = New Thread(AddressOf shutdown)trShutdown.Start()
End If
If receivedData = "###REBOOT###" Then
trReboot = New Thread(AddressOf reboot)trReboot.Start()
End If
If receivedData = "###LOGOFF###" Then
trLogOff = New Thread(AddressOf logoff)trLogOff.Start()
End If
Dim returnedData As String = "###OK###" Dim sw As New StreamWriter(ns)
sw.WriteLine(returnedData)
sw.Flush()
sr.Close()
sw.Close()
ns.Close()
tcpCli.Close()
Loop
tcpList.Stop()
Catch ex As Exception
LISTENING = False
End Try
End Sub
Here port address is taken as 63000.
ServerX Shutdown Request Module
Sub SendMessage()
Dim host As String = txtClientIP.Text
Dim port As Integer = 63000
Try
Dim tcpCli As New TcpClient(host, port)
Dim ns As NetworkStream = tcpCli.GetStream
Dim sw As New StreamWriter(ns)
If rbShutdown.Checked = True Then
sw.WriteLine("###SHUTDOWN###")
End If
If rbReboot.Checked = True Then
sw.WriteLine("###REBOOT###")
End If
If rbLogOff.Checked = True Then
sw.WriteLine("###LOGOFF###")
End If
If rbNothing.Checked = True Then
sw.WriteLine("to")
End If
sw.Flush()
Dim sr As New StreamReader(ns)
Dim result As String = sr.ReadLine()
If result = "###OK###" Then
MsgBox("Operation Performed!!!", MsgBoxStyle.Information, _
"Accepted by client")
End If
sr.Close()
sw.Close()
ns.Close()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Note: remoteClientX
must be run on remote PCs & check the network IP address.
t = objComputer.Win32Shutdown(8 + 4, 0)
The above statement is used to shutdown the system. Here 8
is the code for shutdown and 4
is for Force that is 8+4 : force shutdown, same for reboot and logoff.
Force shutdown: 8+4
Force reboot : 2+4
LogOff : 0
Note: remoteClientX
uses WMI that is Win32_OperatingSystem
class for force shutdown, force reboot, logoff.