Click here to Skip to main content
Click here to Skip to main content

Remote Shutdown or Reboot with Telnet and C#

, 17 Oct 2004
Rate this:
Please Sign up or sign in to vote.
Reboot a computer remotely with Telnet on port 50000, written in C#.


I frequently shutdown services on my computers when working on them and forget to restart them when I am done. It occurred to me that it would be great to be able to secure shell to my Linux system behind my firewall and then telnet on a port to my NT and XP boxes to make them reboot.

Being far more efficient with C#, I decided this would be a great way to learn about creating a Windows service. So I was off and running. The service would require three basic functions: the Windows service itself, the ability to reboot or shutdown the computer, and a listening socket on a thread.

I therefore started with a little quick web search and found the code to restart the computer for C# and wrote a quick test program for it.

Next I looked up how to listen on a socket and read a line with the StreamReader. After testing this little bit of code, it was obvious that it would have to be on a thread so that control could be returned to the windows service. Having tested the parts of my project I then put them all together into one windows service project and added the installer.

This is a new and improved version of the first RemoteShutdown that I created. It now has a configuration file, SHA1 hashed password in the configuration file, and a utility to create the configuration file. The source code for the makeconfig.exe is makeconfig.cs and is compiled at the command prompt with "csc /t:exe makeconfig.cs".

One thing I noticed is that if you have both 1.0 and 1.1 and 2.0 of .net installed make sure you use the right version of InstallUtil. The binary in release directory is compiled with 2003 so you will need to use installutil.exe version 1.1....

Please leave comments so I can find out how useful this program is. I noticed from my private website it had been downloaded over 9000 times. So let me know how it has saved your bacon.

Using the code

  1. Unzip the project into your Visual Studio Projects directory.
  2. From the command prompt (InstallUtil must be version 1.1...) in the release directory, type Installutil RemoteShutdown.exe
  3. Run Makeconfig.exe in the release directory.
  4. Enter your desired password and port.
  5. Then rename the rename to RemoteShutdown.exe.config
  6. Reboot the computer
  7. Goto Administrative Tools/Services and check that the new RemoteShutdown service has started.
  8. To test from the command prompt, type telnet localhost 50000
    type "your password" and the computer will reboot.
  9. To uninstall the service from the release directory type Installutil RemoteShutdown.exe /u

Points of interest

This project demonstrates several interesting capabilities:

  • Reading from configuration file.
  • Calling the Win API to reboot of the computer.
  • SHA1 Hashing of password.
  • Windows Service program.
  • Listening on a port.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Paul J Barrett
Web Developer
United States United States
I have been programming since 1983 when I first programmed on a HeathKit 8088 Breadboard Computer in machine code. Since then I have dabbled with many things. I am extremely fluent with VB6, Access, Sql Server. I am currently programming a major project in C#.
I am also a system administrator for Unix, Linux, MS 4.0 - 2003 and also dabble with CISCO routers and firewalls.

Comments and Discussions

QuestionCommand line? PinsussAnonymous14-Dec-04 15:47 
AnswerRe: Command line? PinmemberPaul J Barrett6-Oct-05 7:01 
Questionweb service? PinsussAnonymous2-Sep-04 10:41 
AnswerRe: web service? PinmemberPaul J Barrett6-Oct-05 7:04 
Your absolutely right. It is not a web service. And you do have to start a new thread for the listener as I recall. I still use this program a lot. Also please note that the Makeconfig.cs needs to be compiled at the command line with csc /t:exe
The addition of the hashed password in the config file makes this much stronger.
Poke tongue | ;-P
Paul J Barrett
IT Director
Las Vegas Athletic Clubs

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    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.150327.1 | Last Updated 18 Oct 2004
Article Copyright 2003 by Paul J Barrett
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid