Hi, Eric
Andy Cheung posted the following last year:
in System.Management, you would set ConnectionOptions.EnablePrivileges
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_OperatingSystem");
osClass.Scope.Options.EnablePrivileges = true;
foreach (ManagementObject os in osClass.GetInstances())
{
ManagementBaseObject outParams = os.InvokeMethod("Reboot", null,
null);
Console.WriteLine("OS is {0}", os["Caption"]);
Console.WriteLine("Executing Win32_OperatingSystem.Reboot returns
{0}", outParams["ReturnValue"]);
}
}
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 --------------------" <
[email protected]>
| Sender: "------------------ eric --------------------" <
[email protected]>
| Subject: Reboot With System.Management
| Date: Thu, 24 Jul 2003 08:57:30 -0700
| Lines: 5
| Message-ID: <
[email protected]>
| 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/EmbwICw3EWATZKra91xved5Pg==
| Newsgroups: microsoft.public.dotnet.general
| Path: cpmsftngxa06.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.general:102311
| NNTP-Posting-Host: TK2MSFTNGXA09 10.40.1.161
| X-Tomcat-NG: microsoft.public.dotnet.general
|
| Any idea how to reboot a givin machine useing the
| ststem.management namespace?
|
|
| thanks eric.
|