Reboot With System.Management

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • ------------------ eric --------------------

    #1

    Reboot With System.Management

    Any idea how to reboot a givin machine useing the
    ststem.manageme nt namespace?


    thanks eric.
  • John Eikanger [MSFT]

    #2
    RE: Reboot With System.Manageme nt

    Hi, Eric

    Andy Cheung posted the following last year:

    in System.Manageme nt, you would set ConnectionOptio ns.EnablePrivil eges
    property to true to enable privileges. There is a bug in .NET Framework
    v1.0 that prevents privileges from working correctly when the calling
    thread is STA. Make your calling thread as MTA as a workaround.

    //[STAThread] // For .NET Framework v1.0, comment this to work
    around in C#. Add "<MTAThread ()> _" in VB.NET.
    public static void Main()
    {
    ManagementClass osClass = new ManagementClass ("Win32_Operati ngSystem");

    osClass.Scope.O ptions.EnablePr ivileges = true;
    foreach (ManagementObje ct os in osClass.GetInst ances())
    {
    ManagementBaseO bject outParams = os.InvokeMethod ("Reboot", null,
    null);
    Console.WriteLi ne("OS is {0}", os["Caption"]);
    Console.WriteLi ne("Executing Win32_Operating System.Reboot returns
    {0}", outParams["ReturnValu e"]);
    }
    }

    Please get back to me and let me know if this works for you.

    HTH,

    John Eikanger
    Microsoft Developer Support

    This posting is provided “AS IS” with no warranties, and confers no rights.
    (c) 2003 Microsoft Corporation. All rights reserved.

    --------------------
    | Content-Class: urn:content-classes:message
    | From: "------------------ eric --------------------" <enpierce@bpa.g ov>
    | Sender: "------------------ eric --------------------" <enpierce@bpa.g ov>
    | Subject: Reboot With System.Manageme nt
    | Date: Thu, 24 Jul 2003 08:57:30 -0700
    | Lines: 5
    | Message-ID: <01a701c351fc$4 99b2a60$a101280 a@phx.gbl>
    | MIME-Version: 1.0
    | Content-Type: text/plain;
    | charset="iso-8859-1"
    | Content-Transfer-Encoding: 7bit
    | X-Newsreader: Microsoft CDO for Windows 2000
    | X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
    | Thread-Index: AcNR/EmbwICw3EWATZKr a91xved5Pg==
    | Newsgroups: microsoft.publi c.dotnet.genera l
    | Path: cpmsftngxa06.ph x.gbl
    | Xref: cpmsftngxa06.ph x.gbl microsoft.publi c.dotnet.genera l:102311
    | NNTP-Posting-Host: TK2MSFTNGXA09 10.40.1.161
    | X-Tomcat-NG: microsoft.publi c.dotnet.genera l
    |
    | Any idea how to reboot a givin machine useing the
    | ststem.manageme nt namespace?
    |
    |
    | thanks eric.
    |

    Comment

    • John Eikanger [MSFT]

      #3
      RE: Reboot With System.Manageme nt

      Hi, Eric

      Andy Cheung posted the following last year:

      in System.Manageme nt, you would set ConnectionOptio ns.EnablePrivil eges
      property to true to enable privileges. There is a bug in .NET Framework
      v1.0 that prevents privileges from working correctly when the calling
      thread is STA. Make your calling thread as MTA as a workaround.

      //[STAThread] // For .NET Framework v1.0, comment this to work
      around in C#. Add "<MTAThread ()> _" in VB.NET.
      public static void Main()
      {
      ManagementClass osClass = new ManagementClass ("Win32_Operati ngSystem");

      osClass.Scope.O ptions.EnablePr ivileges = true;
      foreach (ManagementObje ct os in osClass.GetInst ances())
      {
      ManagementBaseO bject outParams = os.InvokeMethod ("Reboot", null,
      null);
      Console.WriteLi ne("OS is {0}", os["Caption"]);
      Console.WriteLi ne("Executing Win32_Operating System.Reboot returns
      {0}", outParams["ReturnValu e"]);
      }
      }

      Please get back to me and let me know if this works for you.

      HTH,

      John Eikanger
      Microsoft Developer Support

      This posting is provided “AS IS” with no warranties, and confers no rights.
      (c) 2003 Microsoft Corporation. All rights reserved.

      --------------------
      | Content-Class: urn:content-classes:message
      | From: "------------------ eric --------------------" <enpierce@bpa.g ov>
      | Sender: "------------------ eric --------------------" <enpierce@bpa.g ov>
      | Subject: Reboot With System.Manageme nt
      | Date: Thu, 24 Jul 2003 08:57:30 -0700
      | Lines: 5
      | Message-ID: <01a701c351fc$4 99b2a60$a101280 a@phx.gbl>
      | MIME-Version: 1.0
      | Content-Type: text/plain;
      | charset="iso-8859-1"
      | Content-Transfer-Encoding: 7bit
      | X-Newsreader: Microsoft CDO for Windows 2000
      | X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
      | Thread-Index: AcNR/EmbwICw3EWATZKr a91xved5Pg==
      | Newsgroups: microsoft.publi c.dotnet.genera l
      | Path: cpmsftngxa06.ph x.gbl
      | Xref: cpmsftngxa06.ph x.gbl microsoft.publi c.dotnet.genera l:102311
      | NNTP-Posting-Host: TK2MSFTNGXA09 10.40.1.161
      | X-Tomcat-NG: microsoft.publi c.dotnet.genera l
      |
      | Any idea how to reboot a givin machine useing the
      | ststem.manageme nt namespace?
      |
      |
      | thanks eric.
      |

      Comment

      • John Eikanger [MSFT]

        #4
        RE: Reboot With System.Manageme nt

        Hi, Eric

        Andy Cheung posted the following last year:

        in System.Manageme nt, you would set ConnectionOptio ns.EnablePrivil eges
        property to true to enable privileges. There is a bug in .NET Framework
        v1.0 that prevents privileges from working correctly when the calling
        thread is STA. Make your calling thread as MTA as a workaround.

        //[STAThread] // For .NET Framework v1.0, comment this to work
        around in C#. Add "<MTAThread ()> _" in VB.NET.
        public static void Main()
        {
        ManagementClass osClass = new ManagementClass ("Win32_Operati ngSystem");

        osClass.Scope.O ptions.EnablePr ivileges = true;
        foreach (ManagementObje ct os in osClass.GetInst ances())
        {
        ManagementBaseO bject outParams = os.InvokeMethod ("Reboot", null,
        null);
        Console.WriteLi ne("OS is {0}", os["Caption"]);
        Console.WriteLi ne("Executing Win32_Operating System.Reboot returns
        {0}", outParams["ReturnValu e"]);
        }
        }

        Please get back to me and let me know if this works for you.

        HTH,

        John Eikanger
        Microsoft Developer Support

        This posting is provided “AS IS” with no warranties, and confers no rights.
        (c) 2003 Microsoft Corporation. All rights reserved.

        --------------------
        | Content-Class: urn:content-classes:message
        | From: "------------------ eric --------------------" <enpierce@bpa.g ov>
        | Sender: "------------------ eric --------------------" <enpierce@bpa.g ov>
        | Subject: Reboot With System.Manageme nt
        | Date: Thu, 24 Jul 2003 08:57:30 -0700
        | Lines: 5
        | Message-ID: <01a701c351fc$4 99b2a60$a101280 a@phx.gbl>
        | MIME-Version: 1.0
        | Content-Type: text/plain;
        | charset="iso-8859-1"
        | Content-Transfer-Encoding: 7bit
        | X-Newsreader: Microsoft CDO for Windows 2000
        | X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
        | Thread-Index: AcNR/EmbwICw3EWATZKr a91xved5Pg==
        | Newsgroups: microsoft.publi c.dotnet.genera l
        | Path: cpmsftngxa06.ph x.gbl
        | Xref: cpmsftngxa06.ph x.gbl microsoft.publi c.dotnet.genera l:102311
        | NNTP-Posting-Host: TK2MSFTNGXA09 10.40.1.161
        | X-Tomcat-NG: microsoft.publi c.dotnet.genera l
        |
        | Any idea how to reboot a givin machine useing the
        | ststem.manageme nt namespace?
        |
        |
        | thanks eric.
        |

        Comment

        Working...