Click here to Skip to main content
11,929,166 members (58,005 online)
Click here to Skip to main content
Add your own
alternative version


79 bookmarked

Remote Shutdown in VB.NET 2003 and C#.NET 2008

, 3 Jun 2010 CPOL
Rate this:
Please Sign up or sign in to vote.
Shutdown, reboot, and log-off your remote PCs.
Sample screenshot

Sample screenshot


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()
    Dim LISTENING As Boolean
    Dim localhostAddress As IPAddress = IPAddress.Parse(ipAddress.ToString)
    Dim port As Integer = 63000
    ''''''''''' making socket tcpList 
    Dim tcpList As New TcpListener(localhostAddress, port)
      LISTENING = True
      Do While LISTENING
        Do While tcpList.Pending = False And LISTENING = True
          ' Yield the CPU for a while.
        If Not LISTENING Then Exit Do

        Dim tcpCli As TcpClient = tcpList.AcceptTcpClient()
        Dim ns As NetworkStream = tcpCli.GetStream
        Dim sr As New StreamReader(ns)
        ''''''''' get data from server'''''''''''''''
        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###" '& " From Server"
        Dim sw As New StreamWriter(ns)
    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
    Dim tcpCli As New TcpClient(host, port)
    Dim ns As NetworkStream = tcpCli.GetStream

    ' Send data to the client.
    Dim sw As New StreamWriter(ns)
    If rbShutdown.Checked = True Then
    End If

    If rbReboot.Checked = True Then
    End If
    If rbLogOff.Checked = True Then
    End If
    If rbNothing.Checked = True Then
    End If
    ' Receive and display data.
    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

  Catch ex As Exception
  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.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Hari Om Prakash Sharma
Software Developer
India India

You may also be interested in...

Comments and Discussions

QuestionDo you change any permission in Firewall for this program? Pin
Umut Comlekcioglu24-Jul-15 6:49
memberUmut Comlekcioglu24-Jul-15 6:49 
AnswerRe: Do you change any permission in Firewall for this program? Pin
Hari Om Prakash Sharma26-Jul-15 7:55
memberHari Om Prakash Sharma26-Jul-15 7:55 
Questionadd various ip Pin
naq_ninetwo9218-Oct-12 6:20
membernaq_ninetwo9218-Oct-12 6:20 
AnswerRe: add various ip Pin
Hari Om Prakash Sharma5-Dec-12 18:29
memberHari Om Prakash Sharma5-Dec-12 18:29 
GeneralRe: add various ip Pin
naq_ninetwo924-Feb-13 15:34
membernaq_ninetwo924-Feb-13 15:34 
GeneralMy vote of 1 Pin
Аslam Iqbal10-Aug-12 18:46
memberАslam Iqbal10-Aug-12 18:46 
GeneralMy vote of 3 Pin
Vitaly Tomilov24-Jun-12 0:17
memberVitaly Tomilov24-Jun-12 0:17 
GeneralArticle Viewer in C#.Net Pin
Mohammad Afrashteh9-Feb-11 13:36
memberMohammad Afrashteh9-Feb-11 13:36 
GeneralHelp needed Pin
servox4-Aug-10 13:13
memberservox4-Aug-10 13:13 
AnswerRe: Help needed Pin
Hari Om Prakash Sharma11-Aug-10 0:43
memberHari Om Prakash Sharma11-Aug-10 0:43 
GeneralSysinternal did this a long time ago.... Pin
giammin3-Jun-10 22:49
membergiammin3-Jun-10 22:49 
GeneralRe: Sysinternal did this a long time ago.... Pin
Hari Om Prakash Sharma4-Jun-10 6:37
memberHari Om Prakash Sharma4-Jun-10 6:37 
Generalremote shutdown error Pin
alanz858-Apr-10 0:16
memberalanz858-Apr-10 0:16 
GeneralRe: remote shutdown error Pin
Hari Om Prakash Sharma11-Apr-10 4:21
memberHari Om Prakash Sharma11-Apr-10 4:21 
Generalcode Pin
happyankitsanghvi1-Jan-10 23:28
memberhappyankitsanghvi1-Jan-10 23:28 
AnswerRe: code Pin
Hari Om Prakash Sharma4-Jan-10 0:54
memberHari Om Prakash Sharma4-Jan-10 0:54 
Generalplease Pin
Member 40574751-Oct-09 9:28
memberMember 40574751-Oct-09 9:28 
QuestionRemote start up server Pin
kuniyo8-Jul-09 0:11
memberkuniyo8-Jul-09 0:11 
AnswerRe: Remote start up server Pin
Hari Om Prakash Sharma26-Jul-09 20:30
memberHari Om Prakash Sharma26-Jul-09 20:30 
kuniyo wrote:
server is down ?

ServerX? yes, but one question arises how will you give command to system so that application is invoked. simple answer is you have to make another application acts as CommandControl listening off/on activities if main ServerX is down. It depends on port address and process Id. Try this idea.

First and the Foremost: FIGHT TO WIN


GeneralShutdown 1000 XP SP2 PCs Pin
neoice12-Dec-08 23:39
memberneoice12-Dec-08 23:39 
GeneralRe: Shutdown 1000 XP SP2 PCs Pin
Hari Om Prakash Sharma26-Jul-09 20:36
memberHari Om Prakash Sharma26-Jul-09 20:36 
QuestionRemote data on com port Pin
fahadi8610-Dec-08 11:20
memberfahadi8610-Dec-08 11:20 
AnswerRe: Remote data on com port Pin
Hari Om Prakash Sharma17-Dec-08 23:57
memberHari Om Prakash Sharma17-Dec-08 23:57 
Generalmayank Pin
rajnik2-Dec-08 2:11
memberrajnik2-Dec-08 2:11 
GeneralRe: mayank Pin
Hari Om Prakash Sharma15-Dec-08 19:48
memberHari Om Prakash Sharma15-Dec-08 19:48 
GeneralHI Hari Om Pin
chandrikaC31-Aug-08 7:07
memberchandrikaC31-Aug-08 7:07 
AnswerRe: HI Hari Om Pin
Hari Om Prakash Sharma31-Aug-08 19:56
memberHari Om Prakash Sharma31-Aug-08 19:56 
GeneralThank You Hari! Pin
gorpor25-May-08 19:52
membergorpor25-May-08 19:52 
GeneralRe: Thank You Hari! Pin
Hari Om Prakash Sharma27-May-08 21:44
memberHari Om Prakash Sharma27-May-08 21:44 
Generalcode Pin
chanda sharma30-Mar-08 7:02
memberchanda sharma30-Mar-08 7:02 
AnswerRe: code Pin
Hari Om Prakash Sharma30-Mar-08 19:16
memberHari Om Prakash Sharma30-Mar-08 19:16 
Generalhai Pin
sujithomas9-Oct-07 9:09
membersujithomas9-Oct-07 9:09 
GeneralExport data Pin
hungdl22-Sep-07 5:45
memberhungdl22-Sep-07 5:45 
GeneralThnx Hari! Pin
tw1st3d9-May-07 20:18
membertw1st3d9-May-07 20:18 
GeneralRe: Thnx Hari! Pin
Hari Om Prakash Sharma11-May-07 0:21
memberHari Om Prakash Sharma11-May-07 0:21 
GeneralShutdown command Pin
King_kLAx11-Sep-06 1:27
memberKing_kLAx11-Sep-06 1:27 
GeneralRe: Shutdown command Pin
Hari Om Prakash Sharma11-Sep-06 4:43
memberHari Om Prakash Sharma11-Sep-06 4:43 
GeneralRe: Shutdown command Pin
King_kLAx15-Sep-06 1:17
memberKing_kLAx15-Sep-06 1:17 
Generalsome guidance on my project Pin
manish30127-Aug-06 23:34
membermanish30127-Aug-06 23:34 
GeneralRe: some guidance on my project Pin
baljeet_1237-Nov-07 3:53
memberbaljeet_1237-Nov-07 3:53 
GeneralAwesome code! Pin
philipg3630-Jul-06 18:52
memberphilipg3630-Jul-06 18:52 
JokeThank's Hari Om Prakash Sharma! Pin
nguyenkiem25-Apr-06 16:40
membernguyenkiem25-Apr-06 16:40 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.151126.1 | Last Updated 3 Jun 2010
Article Copyright 2006 by Hari Om Prakash Sharma
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid