Restarting the computer programmatically

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • K Viltersten

    Restarting the computer programmatically

    I've found a number of pages describing how
    to restart the computer that my service runs
    on. The nicest one was the Black Wasp's but
    even there, i need to play with C++-like
    looking code. Is it really neccessary?



    I'd like to believe that there's at least a
    convenience wrapper for performing such task
    in C#. Is there? Where?

    --
    Regards
    Konrad Viltersten
    ----------------------------------------
    May all spammers die an agonizing death;
    have no burial places; their souls be
    chased by demons in Gehenna from one room
    to another for all eternity and beyond.


  • Duggi

    #2
    Re: Restarting the computer programmaticall y

    On Oct 6, 2:17 pm, "K Viltersten" <t...@vilterste n.comwrote:
    I've found a number of pages describing how
    to restart the computer that my service runs
    on. The nicest one was the Black Wasp's but
    even there, i need to play with C++-like
    looking code. Is it really neccessary?
    >

    >
    I'd like to believe that there's at least a
    convenience wrapper for performing such task
    in C#. Is there? Where?
    >
    --
    Regards
    Konrad Viltersten
    ----------------------------------------
    May all spammers die an agonizing death;
    have no burial places; their souls be
    chased by demons in Gehenna from one room
    to another for all eternity and beyond.
    use System.Manageme nt class.


    ManagementBaseO bject mbObject = null;
    ManagementClass mcWin32 = new
    ManagementClass ("Win32_Operati ngSystem");
    mcWin32.Get();

    mcWin32.Scope.O ptions.EnablePr ivileges = true;
    ManagementBaseO bject mbObjParams =
    mcWin32.GetMeth odParameters("W in32Shutdown");

    mbObjParams["Flags"] = "1";
    mbObjParams["Reserved"] = "0";

    foreach (ManagementObje ct manObj in
    mcWin32.GetInst ances())
    {
    mbObject = manObj.InvokeMe thod("Win32Shut down",
    mbObjParams, null);
    }

    the above code should work.

    -cnu

    Comment

    • Duggi

      #3
      Re: Restarting the computer programmaticall y

      On Oct 6, 2:17 pm, "K Viltersten" <t...@vilterste n.comwrote:
      I've found a number of pages describing how
      to restart the computer that my service runs
      on. The nicest one was the Black Wasp's but
      even there, i need to play with C++-like
      looking code. Is it really neccessary?
      >

      >
      I'd like to believe that there's at least a
      convenience wrapper for performing such task
      in C#. Is there? Where?
      >
      --
      Regards
      Konrad Viltersten
      ----------------------------------------
      May all spammers die an agonizing death;
      have no burial places; their souls be
      chased by demons in Gehenna from one room
      to another for all eternity and beyond.
      Or else another tweak around is invoke shutdown.exe in a process,
      which shuts system down.

      -Cnu

      Comment

      • K Viltersten

        #4
        Re: Restarting the computer programmaticall y

        use System.Manageme nt class.
        <snip>

        Thanks.


        --
        Regards
        Konrad Viltersten
        ----------------------------------------
        May all spammers die an agonizing death;
        have no burial places; their souls be
        chased by demons in Gehenna from one room
        to another for all eternity and beyond.


        Comment

        • K Viltersten

          #5
          Re: Restarting the computer programmaticall y

          >I'd like to believe that there's at least a
          >convenience wrapper for performing such task
          >in C#. Is there? Where?
          >>
          Or else another tweak around is invoke
          shutdown.exe in a process, which shuts
          system down.
          What are drawbacks with this method? Can it
          lead to the computer being stuck TRYING to
          restart and not being able to kill some of
          the processes?

          I need something that basically ensures that
          "the cord is unplugged".

          --
          Regards
          Konrad Viltersten
          ----------------------------------------
          May all spammers die an agonizing death;
          have no burial places; their souls be
          chased by demons in Gehenna from one room
          to another for all eternity and beyond.


          Comment

          • Duggi

            #6
            Re: Restarting the computer programmaticall y

            On Oct 6, 8:03 am, "K Viltersten" <t...@vilterste n.comwrote:
            I'd like to believe that there's at least a
            convenience wrapper for performing such task
            in C#. Is there? Where?
            >
            Or else another tweak around is invoke
            shutdown.exe in a process, which shuts
            system down.
            >
            What are drawbacks with this method? Can it
            lead to the computer being stuck TRYING to
            restart and not being able to kill some of
            the processes?
            >
            I need something that basically ensures that
            "the cord is unplugged".
            >
            --
            Regards
            Konrad Viltersten
            ----------------------------------------
            May all spammers die an agonizing death;
            have no burial places; their souls be
            chased by demons in Gehenna from one room
            to another for all eternity and beyond.
            what is "the cord is unplugged" means?? :-( (I am not good at
            English may be)

            -Cnu

            Comment

            • K Viltersten

              #7
              Re: Restarting the computer programmaticall y

              >>>I'd like to believe that there's at least a
              >>>convenienc e wrapper for performing such task
              >>>in C#. Is there? Where?
              >>>
              >>Or else another tweak around is invoke
              >>shutdown.ex e in a process, which shuts
              >>system down.
              >>
              >What are drawbacks with this method? Can it
              >lead to the computer being stuck TRYING to
              >restart and not being able to kill some of
              >the processes?
              >>
              >I need something that basically ensures that
              >"the cord is unplugged".
              >
              what is "the cord is unplugged" means?? :-(
              (I am not good at English may be)
              Try to picture what happens if you UNPLUG your
              computer (desktop, not laptop). That's what i
              ment to cause. Guaranteed reboot.

              As for the phrase - it's probably my english,
              not yours, that is to blame, hehe.

              --
              Regards
              Konrad Viltersten
              ----------------------------------------
              May all spammers die an agonizing death;
              have no burial places; their souls be
              chased by demons in Gehenna from one room
              to another for all eternity and beyond.


              Comment

              • Duggi

                #8
                Re: Restarting the computer programmaticall y

                On Oct 8, 9:59 am, "K Viltersten" <t...@vilterste n.comwrote:
                >>I'd like to believe that there's at least a
                >>convenience wrapper for performing such task
                >>in C#. Is there? Where?
                >
                >Or else another tweak around is invoke
                >shutdown.exe in a process, which shuts
                >system down.
                >
                What are drawbacks with this method? Can it
                lead to the computer being stuck TRYING to
                restart and not being able to kill some of
                the processes?
                >
                I need something that basically ensures that
                "the cord is unplugged".
                >
                what is "the cord is unplugged" means??  :-(
                (I am not good at English may be)
                >
                Try to picture what happens if you UNPLUG your
                computer (desktop, not laptop). That's what i
                ment to cause. Guaranteed reboot.
                >
                As for the phrase - it's probably my english,
                not yours, that is to blame, hehe.
                >
                --
                Regards
                Konrad Viltersten
                ----------------------------------------
                May all spammers die an agonizing death;
                have no burial places; their souls be
                chased by demons in Gehenna from one room
                to another for all eternity and beyond.- Hide quoted text -
                >
                - Show quoted text -
                As far as I know, if You wanted a guaranteed reboot, the only approach
                is load all the current running processes that are running and start
                killing them one after another.

                I strongly do not recommend this as the side effects are generally
                more than the advantage you gain.

                The earlier approach is good enough, as even if some proceses are not
                killed, and system system does not shut down, my support guys can
                always request the customer to restart the machine carefully. (To the
                best fo my knowledge, a process can not be stopped because it has
                something important to do. or current user do not have permision to do
                so)

                If you want code for get all the processes and kill them one after
                anthor, I can write send it to you.

                -Cnu

                Comment

                • Duggi

                  #9
                  Re: Restarting the computer programmaticall y

                  On Oct 8, 10:08 am, Duggi <DuggiSrinivasa ...@gmail.comwr ote:
                  On Oct 8, 9:59 am, "K Viltersten" <t...@vilterste n.comwrote:
                  >
                  >
                  >
                  >
                  >
                  >>>I'd like to believe that there's at least a
                  >>>convenienc e wrapper for performing such task
                  >>>in C#. Is there? Where?
                  >
                  >>Or else another tweak around is invoke
                  >>shutdown.ex e in a process, which shuts
                  >>system down.
                  >
                  >What are drawbacks with this method? Can it
                  >lead to the computer being stuck TRYING to
                  >restart and not being able to kill some of
                  >the processes?
                  >
                  >I need something that basically ensures that
                  >"the cord is unplugged".
                  >
                  what is "the cord is unplugged" means??  :-(
                  (I am not good at English may be)
                  >
                  Try to picture what happens if you UNPLUG your
                  computer (desktop, not laptop). That's what i
                  ment to cause. Guaranteed reboot.
                  >
                  As for the phrase - it's probably my english,
                  not yours, that is to blame, hehe.
                  >
                  --
                  Regards
                  Konrad Viltersten
                  ----------------------------------------
                  May all spammers die an agonizing death;
                  have no burial places; their souls be
                  chased by demons in Gehenna from one room
                  to another for all eternity and beyond.- Hide quoted text -
                  >
                  - Show quoted text -
                  >
                  As far as I know, if You wanted a guaranteed reboot, the only approach
                  is load all the current running processes that are running and start
                  killing them one after another.
                  >
                  I strongly do not recommend this as the side effects are generally
                  more than the advantage you gain.
                  >
                  The earlier approach is good enough, as even if some proceses are not
                  killed, and system system does not shut down, my support guys can
                  always request the customer to restart the machine carefully. (To the
                  best fo my knowledge, a process can not be stopped because it has
                  something important to do. or current user do not have permision to do
                  so)
                  >
                  If you want code for get all the processes and kill them one after
                  anthor, I can write send it to you.
                  >
                  -Cnu- Hide quoted text -
                  >
                  - Show quoted text -
                  Hey be I am wrong, the above as per my best knowledge goes.

                  -Cnu

                  Comment

                  Working...