![]() |
General Reading »
Hardware & System »
System
Intermediate
Remote Shutdown or Reboot with Telnet and C#By Paul J BarrettReboot a computer remotely with Telnet on port 50000, written in C#. |
C#.NET 1.0, .NET 1.1, Win2K, WinXPVS.NET2003, Dev
|
|
Advanced Search Add to IE Search |
|
|
|
||||||||||||||||
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 VS.net 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.
This project demonstrates several interesting capabilities:
| You must Sign In to use this message board. | |||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||
General
News
Question
Answer
Joke
Rant
Admin
|
PermaLink |
Privacy |
Terms of Use
Last Updated: 17 Oct 2004 Editor: Nishant Sivakumar |
Copyright 2003 by Paul J Barrett Everything else Copyright © CodeProject, 1999-2009 Web13 | Advertise on the Code Project |