Click here to Skip to main content
16,019,619 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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?
Posted

1 solution

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[^])
VB
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

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.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900