远程关机PC使用C#窗口? [英] Remote shutdown PC using C# windows form?

查看:158
本文介绍了远程关机PC使用C#窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用c#通过命令提示符远程关闭电脑,我已经做了一些搜索,并找到了这种代码。

I'm trying to shutdown PC remotely programmatically using c# via command prompt and I already done a few search and found out this kind of codes.

System.Diagnostics.Process.Start("shutdown", "/s");

因为它不会spicify任何pc的关机,所以我试图更改这些代码我认为满足我的目标。但结果是这不工作。

And since it doesn't spicify any pc which to shutdown so I tried changing that codes to this codes which I think satisfy my goal. But it turns out that this doesn't work.

System.Diagnostics.Process.Start("shutdown", "/s /m \\192.168.1.21 /t 5 /c 'Shutdown in 5 seconds'");

无C#中的异常只是不关闭。

NO Exception in C# it just don't shutdown.

我也试试这个,但没有运气。

I also try this but no luck.

 System.Diagnostics.Process.Start("shutdown /s /m \\192.168.1.21 /t 5 /c 'Shutdown in 5 seconds'");

C#异常系统找不到指定的文件。

C# Exception "The system cannot find file specified".

编辑:

我忘了告诉你,我alredy设置我的远程计算机和服务器的方式,无法互相连接,例如关闭防火墙,配置本地系统策略以及更改网络和共享中心。

I forgot to tell you that I alredy set up my remote computer and server the way that it will not fail to connect to each other such as turning off the firewall, configuring Local system policy and changing network and sharing center.

推荐答案

可以看看下面的SO帖子。

You can have a look at the SO post below. It talks about rebooting a remote machine.

WMI重新启动远程计算机

WMI to reboot remote machine

如果您查看 Win32Shutdown 方法


Shutdown => 1 & Reboot => 2(0x2)

Shutdown => 1 (0x1) & Reboot => 2 (0x2)

所以在上面的SO链接中,你必须更改

So in the SO link above you will have to change

 // Add the input parameters.
 inParams["Flags"] =  2; //Reboot

 // Add the input parameters.
 inParams["Flags"] =  1; //Shutdown

这篇关于远程关机PC使用C#窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆