473,386 Members | 1,758 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Reboot With System.Management

Any idea how to reboot a givin machine useing the
ststem.management namespace?
thanks eric.
Nov 22 '05 #1
3 4773
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 --------------------" <en******@bpa.gov>
| Sender: "------------------ eric --------------------" <en******@bpa.gov>
| Subject: Reboot With System.Management
| Date: Thu, 24 Jul 2003 08:57:30 -0700
| Lines: 5
| Message-ID: <01****************************@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/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.
|

Nov 22 '05 #2
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 --------------------" <en******@bpa.gov>
| Sender: "------------------ eric --------------------" <en******@bpa.gov>
| Subject: Reboot With System.Management
| Date: Thu, 24 Jul 2003 08:57:30 -0700
| Lines: 5
| Message-ID: <01****************************@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/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.
|

Nov 22 '05 #3
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 --------------------" <en******@bpa.gov>
| Sender: "------------------ eric --------------------" <en******@bpa.gov>
| Subject: Reboot With System.Management
| Date: Thu, 24 Jul 2003 08:57:30 -0700
| Lines: 5
| Message-ID: <01****************************@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/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.
|

Nov 22 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: ---------- Eric ---------- | last post by:
How would i go about rebooting a remote computer from code running on this local computer? Bacsically i have a service running on machine A, it checks the status of a service on machine B. If...
1
by: ------------------ eric -------------------- | last post by:
Any idea how to reboot a givin machine useing the ststem.management namespace? thanks eric.
1
by: eric | last post by:
I have a need to reboot a remote machine from code that is running on a local machine. I would assume that i need to use WMI and the system.management namespace. Any ideas? Code Samples? ...
0
by: Allan Bredahl | last post by:
Hi All I am trying to construct an application that is able to cancel a machine shutdown, reboot or logoff. And after performing some stuff to perform the original shutdown order :...
0
by: Manoj Nair | last post by:
Hi, I am writing a console application using WMI with C# . Development is for Windows XP machine. One of the methods requires to reboot the local terminal. In my application I make a call to...
6
by: Herbert VON GRÜNENWALD | last post by:
in c++ it was ExitWindowsEx() thanks
3
by: sam | last post by:
I found reboot script at TechNet and I wonder how to apply in VB.Net? Reboot Coding ************ strComputer = "." Set objWMIService = GetObject("winmgmts:" _ &...
1
by: Aaron | last post by:
Not sure if this is the best spot to post this question, but I am not going to pay money to ask an installation question.... Anyways I am trying to install C# standard 2003 and it analyzes the...
8
by: Avi G | last post by:
Hi, what is the quick code in C# for reboot local machine? Thanks.
1
by: =?Utf-8?B?SmVmZg==?= | last post by:
Is there a .NET class for rebooting XP and specifying the program to run on reboot? Thanks, jeff
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.