Search code examples
c#remoting

Is it possible to Shut down a 'remote PC' programatically through .net application?


I am wondering, Is it possible to Shut down a remote PC programatically through .net application?

If yes, how it can be?


Solution

  • See this KB article

    For example:

    System.Diagnostics.Process proc = new System.Diagnostics.Process();
    proc.EnableRaisingEvents=false;
    proc.StartInfo.FileName = "shutdown.exe";
    proc.StartInfo.Arguments = @"\\computername /t:120 ""The computer is shutting down"" /y /c";
    proc.Start();
    

    The example above uses the following switches (excerpted from the linked article)

    • \\computername: Use this switch to specify the remote computer to shut down. If you omit this parameter, the local computer name is used.

    • /t:xx: Use this switch to specify the time (in seconds) after which the computer is shut down. The default is 20 seconds.

    • "The computer is shutting down": Use this switch to specify a message during the shutdown process. The maximum number of characters that the message can contain is 127.

    • /y: Use this switch to force a "yes" answer to all queries from the computer.

    • /c: Use this switch quit all running programs. If you use this switch, Windows forces all programs that are running to quit. The option to save any data that may have changed is ignored. This can result in data loss in any programs for which data is not previously saved.