先说windows
当然利用远程用wmi关机了,但当用C#直接调用时,总是不成功,
换成powersehll远程 执行却没有问题 ,原因我也不知。好像跟系统有关,所以直接用powershell好了。用C#执行powershell可以看另一篇文章:http://jiamaocode.com/Conts/1193/1193.htmlpowersehll关机却本如下:$key = "HKLM:\SOFTWARE\Microsoft\PowerShell\1\ShellIds"
Set-ItemProperty $key ConsolePrompting True
$pingResult = Test-Connection -ComputerName $computer -Count 1 -Quiet
if ($pingResult)
{
$os = Get-WmiObject Win32_OperatingSystem -computerName $computer -Credential $cred
}
$info=$os.Win32Shutdown(5)其中参数:$computer ,$cred
将由C#传进来要个保证您的机器能够远程执行wmi,具体操作网上有很多吧。
下面就不多说了。。具体看源码。接着说linux的远程关机。
其实linux简单得多,注意:被关机的linux系统必须启用服务sshd
这里要用到开源的项目:http://jiamaocode.com/ProCts/1213/1213.html 我以前写的只要对linux远程执行shell.Shell("halt -p");//关机    
命令即可所有的关机都必须用管理员帐户才行,windows的最好用administrator,linux的最好用root
源码:http://jiamaocode.com/Conts/2011/01/02/1329/1329.html