可以参考一下,哈转:Windows管理仪器(简称为 WMI)提供了许多的属性和方法,但是却不能让我关掉我们学校的机器。现在你可以使用WMI来远程重启服务器。当然做这些你必须有一个管理员帐号。
在下面的代码中,你得指定新的IP、用户名、密码等,不能照抄我的哦。 WMI是一个很好的工具,但是也是一个潜在的安全问题。如果你没有必要使用WMI,那么你最好还是关闭它。 代码如下://展示如何远程重启服务器//Written 02/01/02 By John O'Donnell - [email protected] using System;
using System.Management; namespace WMI3
{
///
/// Summary description for Class1.
/// class Class1
{
static void Main(string[] args)
{
Console.WriteLine("Computer details retrieved using Windows Management Instrumentation (WMI)");
Console.WriteLine("mailto:Written%2002/01/02%20By%20John%20O'Donnell%20-%[email protected]");
Console.WriteLine("========================================
=================================");
//连接远程计算机
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); //查询远程计算机
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());
}
}
}
}
在下面的代码中,你得指定新的IP、用户名、密码等,不能照抄我的哦。 WMI是一个很好的工具,但是也是一个潜在的安全问题。如果你没有必要使用WMI,那么你最好还是关闭它。 代码如下://展示如何远程重启服务器//Written 02/01/02 By John O'Donnell - [email protected] using System;
using System.Management; namespace WMI3
{
///
/// Summary description for Class1.
/// class Class1
{
static void Main(string[] args)
{
Console.WriteLine("Computer details retrieved using Windows Management Instrumentation (WMI)");
Console.WriteLine("mailto:Written%2002/01/02%20By%20John%20O'Donnell%20-%[email protected]");
Console.WriteLine("========================================
=================================");
//连接远程计算机
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); //查询远程计算机
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());
}
}
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货