Click here to Skip to main content
6,292,426 members and growing! (10,042 online)
Email Password   helpLost your password?
Languages » VB.NET » General     Intermediate License: The Code Project Open License (CPOL)

Remote Shutdown in VB.NET 2003

By Hari Om Prakash Sharma

Shutdown, reboot, and log-off your remote PCs.
VB.NET 1.1, Win2K, WinXP, Win2003, WinForms, VS.NET2003, Dev
Posted:23 Mar 2006
Views:54,236
Bookmarked:38 times
Unedited contribution
Announcements
Loading...
 
Search    
Advanced Search
printPrint   Broken Article?Report       add Share
  Discuss Discuss   Recommend Article Email
24 votes for this article.
Popularity: 4.83 Rating: 3.50 out of 5
4 votes, 16.7%
1
1 vote, 4.2%
2
2 votes, 8.3%
3
4 votes, 16.7%
4
13 votes, 54.2%
5

Sample screenshot

Sample screenshot

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
    '' PORT ADDRESS
    ''''''''''' making socket tcpList 
    ''''''''''''''''
    Dim tcpList As New TcpListener(localhostAddress, port)
    Try
      tcpList.Start()
      LISTENING = True
      Do While LISTENING
        Do While tcpList.Pending = False And LISTENING = True
          ' Yield the CPU for a while.
          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)
        ''''''''' 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)
        sw.WriteLine(returnedData)
        sw.Flush()
        sr.Close()
        sw.Close()
        ns.Close()
        tcpCli.Close()
      Loop
      tcpList.Stop()
    Catch ex As Exception
      'error
      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

    ' Send data to the client.
    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()
    ' 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

    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)

obove statement is used to shutdown the system. Here 8 is the code for shutdown & 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 ueses WMI that is Win32_OperatingSystem class for force shutdown,force reboot, logoff.

License

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


Member
Hi, I am HARI OM PRAKASH, E-security Scientist, C-DAC(INDIA).


My job is to monitor malicious activities of attackers, attack/attacker profiling, designing and developing tools.
Languages Known C#.NET, VB.NET,ASP.NET,PHP,SQL,JAVA,LINUX,WINDOWS.

Ask freely any time, any question...!!!
Occupation: Software Developer
Company: C-DAC
Location: India India

Other popular VB.NET articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 22 of 22 (Total in Forum: 22) (Refresh)FirstPrevNext
GeneralShutdown 1000 XP SP2 PCs Pinmemberneoice23:39 12 Dec '08  
QuestionRemote data on com port Pinmemberfahadi8611:20 10 Dec '08  
AnswerRe: Remote data on com port PinmemberHari Om Prakash Sharma23:57 17 Dec '08  
Generalmayank Pinmemberrajnik2:11 2 Dec '08  
GeneralRe: mayank PinmemberHari Om Prakash Sharma19:48 15 Dec '08  
GeneralHI Hari Om PinmemberchandrikaC7:07 31 Aug '08  
AnswerRe: HI Hari Om PinmemberHari Om Prakash Sharma19:56 31 Aug '08  
GeneralThank You Hari! Pinmembergorpor19:52 25 May '08  
GeneralRe: Thank You Hari! PinmemberHari Om Prakash Sharma21:44 27 May '08  
Generalcode Pinmemberchanda sharma7:02 30 Mar '08  
AnswerRe: code PinmemberHari Om Prakash Sharma19:16 30 Mar '08  
Generalhai Pinmembersujithomas9:09 9 Oct '07  
GeneralExport data Pinmemberhungdl5:45 22 Sep '07  
GeneralThnx Hari! Pinmembertw1st3d20:18 9 May '07  
GeneralRe: Thnx Hari! PinmemberHari Om Prakash Sharma0:21 11 May '07  
GeneralShutdown command PinmemberKing_kLAx1:27 11 Sep '06  
GeneralRe: Shutdown command PinmemberHari Om Prakash Sharma4:43 11 Sep '06  
GeneralRe: Shutdown command PinmemberKing_kLAx1:17 15 Sep '06  
Generalsome guidance on my project Pinmembermanish30123:34 27 Aug '06  
GeneralRe: some guidance on my project Pinmemberbaljeet_1233:53 7 Nov '07  
GeneralAwesome code! Pinmemberphilipg3618:52 30 Jul '06  
JokeThank's Hari Om Prakash Sharma! Pinmembernguyenkiem16:40 25 Apr '06  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 23 Mar 2006
Editor:
Copyright 2006 by Hari Om Prakash Sharma
Everything else Copyright © CodeProject, 1999-2009
Web09 | Advertise on the Code Project