如何在c#中使用wcf打开和关闭服务器? [英] How to on and shutdown a server using wcf in c# ?

查看:157
本文介绍了如何在c#中使用wcf打开和关闭服务器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我需要在服务器系统上,然后需要关闭服务器系统。



我试过shutdown -s -f -m \\192.168.11.99,shutdown -s -f -t 00 -m \\192.168.11.99

但它没有工作。任何人都可以建议我正确的答案吗?

Hi ,

I need to on the server system and then need to sht down the server system.

I tried shutdown -s -f -m \\192.168.11.99,shutdown -s -f -t 00 -m \\192.168.11.99
but it does not work. can any one suggest me the correct answer?

推荐答案

您的原始帖子与WCF无关,更不用说C#或编程。只有当您是远程服务器上的管理员,并且您模拟该管理员用户,RPC服务正在运行,并且没有阻止您的防火墙时,您才可以远程关闭计算机。



如果你想从代码中执行此操作,可以使用WMI作为示例(http://msdn.microsoft.com/en-us/library/aa394591(v=vs.85).aspx [ ^ ])

Your original post has nothing to do with WCF, even less with C# or programming. You can shutdown a machine remotely only if you are admin on the remote server, and you impersonate that admin user, the RPC service is running, and there is no firewall hindering you.

If you want to do this from code, you could use WMI for example (http://msdn.microsoft.com/en-us/library/aa394591(v=vs.85).aspx[^])
strComputer = "atl-dc-01"
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate,(Shutdown)}!\\" & _
        strComputer & "\root\cimv2")
Set colOperatingSystems = objWMIService.ExecQuery _
    ("Select * from Win32_OperatingSystem")
For Each objOperatingSystem in colOperatingSystems
    ObjOperatingSystem.Shutdown(1)
Next



这很容易在c#中转录。点击此处查看示例: http://www.dlssoftwarestudios.com/simple-wmi-with-c/ [ ^ ]



当然,您可以为此目的公开WCF服务,但我认为这不值得尝试。



打开它是一项有点不同的任务,取决于硬件制造商。以HP为例,您可以使用iLO,但使用API​​并不是那么简单。


This is quite easy to transcribe in c#. Check here for examples: http://www.dlssoftwarestudios.com/simple-wmi-with-c/[^]

Of course, you could expose a WCF service for this purpose, but I don't think it's worth trying.

Switching it on is a little bit different task, and depends on the hardware manufacturer. With HP for example you can use the iLO, but it is not so simple to use the API.


这篇关于如何在c#中使用wcf打开和关闭服务器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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