SIGN UP MEMBER LOGIN:    
ARTICLE

Rebooting a Remote Server using WMI

Posted by John O Donnell Articles | Networking February 04, 2002
Windows Management Instrumentation or WMI holds many surprises and features but when my colleagues machine rebooted even I was surprised.
Reader Level:
Download Files:
 

Windows Management Instrumentation or WMI holds many surprises and features but when my colleagues machine rebooted even I was surprised. Using WMI allows you to create management type applications and of course being able to reboot a remote computer is a necessary feature. Of course it requires you have an admin logon account to the machine.

In this code written with Beta 2 you will need to change the username, password and ip address to access your own machines.

While WMI is a great feature it may be exposed as a security risk. If you have no intention of using its features on your network you may want to disable it.

Enjoy

//WMI3
//Demonstrates how to remotely reboot a computer on the network
//Written 02/01/02 By John O'Donnell - csharpconsulting@hotmail.com
using System;
using System.Management;
namespace WMI3
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
static void Main(string[] args)
{
Console.WriteLine("Computer details retrieved using Windows Management Instrumentation (WMI)");
Console.WriteLine("Written 02/01/02 By John O'Donnell - csharpconsulting@hotmail.com");
Console.WriteLine("========================================
=================================");
//Connect to the remote computer
ConnectionOptions co = new ConnectionOptions();
co.Username = "john";
co.Password = "john";
System.Management.ManagementScope ms =
new
System.Management.ManagementScope("\\\\192.168.1.2\\root\\cimv2", co);
//Query remote computer across the connection
System.Management.ObjectQuery oq = new System.Management.ObjectQuery
("SELECT * FROM Win32_OperatingSystem");
ManagementObjectSearcher query1 =
new ManagementObjectSearcher(ms,oq);
ManagementObjectCollection queryCollection1 = query1.Get();
foreach( ManagementObject mo in queryCollection1 )
{
string[] ss={""};
mo.InvokeMethod("Reboot",ss);
Console.WriteLine(mo.ToString());
}
}
}
}

Login to add your contents and source code to this article
share this article :
post comment
 
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor
PREMIUM SPONSORS
  • ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications. Visit DynamicPDF here
    The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
Team Foundation Server Hosting
Become a Sponsor