Shutdown.exe problems

Process shutdown = new Process();

shutdown.StartInfo.FileName = "C:/WINDOWS/System32/Shutdown.exe";

shutdown.StartInfo.Arguments = "-s -f -t 20 -m \\deruu";

shutdown.Start();

I can get it to log me out using argument -l only, but with that I only get a "Frozen" cmd window titled "Shutdown.exe" and nothing happens.


Answer this question

Shutdown.exe problems

  • robinjam

    Damn, I suspected it had something to do with that but figured C# would ignore it if it wasn't followed something valid.

    Thanks for the help

    edit: oh yeah, On my list over connected computers they appear like this: MSHOME/DERUU, How can I get rid of "MSHOME/"

    editagain: nevermind, problem solved.

  • yatingg

    Now I get this:

    Error 1 No overload for method 'Process' takes '1' arguments C:\Documents and Settings\Deru\Mina dokument\Visual Studio 2005\Projects\Network watch\Network watch\Form1.cs 56 32 Network watch


    Error 2 'System.Environment' does not contain a definition for 'GetFolder' C:\Documents and Settings\Deru\Mina dokument\Visual Studio 2005\Projects\Network watch\Network watch\Form1.cs 57 64 Network watch

    If I my code it works as long as I don't use -m //deruu though I need it for my little project



  • DQM

    Opens up shutdown.exe but nothing happens

  • enric vives

    Hy, Friend
    I read this blog.
    I have one link of same forum so,
    try this one.

    http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=243746&SiteID=1




  • prujohn

    its command driven so you need to open up an instance of command prompt (start > run > cmd) then type in shutdown + arguments. Example:

    start > run > cmd

    then in the command window that will pop up, type:

    shutdown /s /f /t 20 /m \\deruu



  • cdolor

    hang on, I think I know where the problem is.

    Process shutdown = new Process();

    shutdown.StartInfo.FileName = "C:/WINDOWS/System32/Shutdown.exe";

    shutdown.StartInfo.Arguments = "-s -f -t 20 -m \\deruu";

    shutdown.Start();

    the bold part should be 4 backslashes overall since a backslash in C# is an escape character so it should be:

    \\\\deruu

    does this work now



  • finialscraps

    Yes I know, that works.. But I want to be able to execute it from my application

  • atypoli

    try this:

    Process shutdown = new Process("shutdown");

    shutdown.StartInfo.WorkingDirectory = Environment.GetFolder(Environment.SpecialFolder.System);

    shutdown.StartInfo.Arguments = "/s /f /t 20 /m \\deruu";

    shutdown.Start();

    you may want to try to take out the /f switch just in case and see what happens, it could be the fact that there is an application which has hung or something in the back preventing it from shutting down. You also need to have permission to shutdown the machine I think but if this was the case then you should have recieved a warning/error about it.



  • Fredrik Kronander

    my apologies, seems to be a typo for GetFolder, it should be Environment.GetFolderPath. And again, my apologies, the Process class does not take the overload but it should have been the ProcessStartInfo class.

    So even doing it this way shouldnt make much difference:

    ProcessStartInfo thePSI = new ProcessStartInfo("shutdown.exe");

    thePSI.WorkingDirectory = Environment.GetFolderPath(Environment.SpecialFolder.System);

    thePSI.Arguments = "args here";

    Process.Start(thePSI);

    I am wondering, what happens when you do this manually from the command prompt including all the parameters you used in the code where it appears not to work



  • Seraphino

     TechedRonan wrote:


    edit: oh yeah, On my list over connected computers they appear like this: MSHOME/DERUU, How can I get rid of "MSHOME/"

    editagain: nevermind, problem solved.

    Try Environment.UserDomainName !

    MSDN Reference:

    "The UserDomainName property first attempts to get the domain name component of the Windows NT 4.0 account name for the current user. The account name is formatted as domain name, the '\' character, and user name. If that attempt fails, this property attempts to get the domain name associated with the user name provided by the UserName property. If that attempt fails because the host computer is not joined to a domain, then the host computer name is returned."

    I hope this will work!

    Best Regards,

    edit: I did not read this "nevermind, problem solved."

    Sorry! :)



  • Shutdown.exe problems