views:

2193

answers:

7

I want to shut down the remote computer (ex. a computer connected in LAN.) I have tried a lot but I could not find the solution. Does anyone have an idea on how to shut down the remote computer? Any language would work.

+1  A: 

Invoke shutdown -s -m \\computername command through a primitive used to start processes (like Process.Start() or CreateProcess()).

sharptooth
+6  A: 

Assuming a windows box.

In VB.NET or c#

Process.Start("shutdown","-s -m \\Machine");

Should do the trick.

See
http://msdn.microsoft.com/en-us/library/system.diagnostics.process.start.aspx
http://www.ss64.com/nt/shutdown.html

EDIT: Note - shutdown.exe was only available in Resource Kits prior to Windows 2003

Rob Stevenson-Leggett
I believe that `shutdown.exe` was only available in Resource Kits prior to Windows 2003 (after which it is available in the default Windows installation).
ephemient
@ephement: shutdown.exe is present on Windows XP. It may also be present on Windows 2000.
R. Bemrose
+5  A: 

You can connect to any computer on the domain and shut it down using the Win32Shutdown method of the WMI class Win32_OperatingSystem. In .NET you access WMI through the System.Management namespace.

Jakob Christensen
A: 

Not sure if this code sample works, but it illustrates how you can use WMI to remotely shutdown a computer.

Will
+1  A: 

If the remote computer is a Windows box you can use WMI (Windows Management Instrumentation).

http://msdn.microsoft.com/en-us/library/aa394582.aspx

Use the Reboot() method of the Win32_OperatingSystem class. You could do this for example using Windows Script, C#, VB .net

phatoni
+1  A: 
  1. Connect to the host through SSH
  2. user@domain:~$ sudo shutdown -h now
Fedyashev Nikita
A: 

From a linux box [net rpc shutdown]

or call initiateSystemShutdown

Brad Gilbert