Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Remote windows shutdown method

Status
Not open for further replies.

baddos

MIS
Dec 3, 2002
2,360
US
Does anyone have a good idea on how to shutdown remote Windows 2000/XP machines? I'm trying to write a small little utiltiy that will shutdown people's machines that leave work and forget to turn them off. I've researched a little bit into WMI, but it seems a little too involved and a much simpler object would be around.
 
Yup, there is an easier way. (If you have Windows XP or Server 2003)

start->run
shutdown -i

pretty self explanatory from there. You need to have admin access on the target machine, and some firewalls will block the call, so you may have to do some research to see if the users have a personal firewall (ie: Windows Firewall) and what port would need to be opened for this to work.

If you want to script it, you can type shutdown /? at a command prompt and get more info. Then just throw together a .Bat file to do the work.

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
Go to and download PsTools. There is a utility called 'psexec' that you can call remotely anywhere on your network. Just shell it from your app and pass the correct parameters. Tons of other cool utilities as well. Microsoft bought SysInternals, so it is their site.
 
Well I was looking to do this all from a service or script to run on a server that is automated. Create a whitelist for allowed machines to stay on, and shut all the other ones off. Was looking into various ways of scanning the network list to see which ones are on and shutdown the ones not on the whitelist. Doing this all automatically via a script or program is key, as I don't want to turn into a Nanny for all the employees. LOL
 
How many PCs are we talking about? If you have a standard naming convention and relatively low inventory turn over, just sticking all of the PC names in a batch file for shutdown would be easy enough.

The jump from a static-maintained batch to a fully dynamic application is a pretty big one. If you do want to make that jump, look into WMI. I know it can get you machine names, and I think it can do shut downs. Even if it can't do shutdowns, you can still use it to get the PC names dynamically and call the shutdown app.

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
Get the entire PStools utilities. A combination of the PSLoggedOn.exe and the PsShutdown utility, you can accomplish this fairly easy. You would be able to have this on a server and automated via a simple vb.net app and/or service. Download the PSTools and read up on the PSLoggedOn and PSShutdown. If you wanted, PSShutdown can even reboot every PC on the domain. In addition, it can exit applications gracefully on those machines, logoff users, etc. Read the help file that comes with the pstools, there are specific examples of what you want. Throw that into an app. Shell the commands from your server and you are done. :)
 
I ended up just using the shutdown.exe builtin to Windows.

Code:
Dim objShutdown As New System.Diagnostics.ProcessStartInfo("shutdown.exe")
objShutdown.Arguments = "-s -t 120 -f -c ""Your computer is being turned off by the IT department. Please save your work."" -m \\" & strComputer
 
Oops... Forgot to add the important part.

Code:
System.Diagnostics.Process.Start(objShutdown)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top