先说windows
当然利用远程用wmi关机了,但当用C#直接调用时,总是不成功,
换成powersehll远程 执行却没有问题 ,原因我也不知。好像跟系统有关,所以直接用powershell好了。
用C#执行powershell可以看另一篇文章:http://jiamaocode.com/Conts/1193/1193.html
powersehll关机却本如下:
$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简单
C#实现远程关机功能(windows和linux)
最新推荐文章于 2025-03-16 11:01:46 发布