使用System.Management写了一个远程关机(重启)的程序,发现对NT4无效,NT4下没有WMI吗? 我知道了,刚才翻出VS7第五张盘发现了WMI这个目录下的wmicore.exe,这就是为NT4准备的WMI核心组件!!那么WIN98和WINXP呢,如果他们没有用户WMI又如何用得上? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 windows 2000以上的都自动装了的。98就不晓得了。。 我试过下面的代码,不能使用!using System ;using System.Drawing ;using System.Collections ;using System.ComponentModel ;using System.Windows.Forms ;using System.Data ;using System.Management;namespace rebootremote{/// <summary>/// Form1 的摘要说明。/// </summary>public class frmreboot : System.Windows.Forms.Form{private System.Windows.Forms.Label label1;private System.Windows.Forms.Label label2;private System.Windows.Forms.Label label3;private System.Windows.Forms.TextBox textBox1;private System.Windows.Forms.TextBox textBox2;private System.Windows.Forms.TextBox textBox3;private System.Windows.Forms.Button button1;/// <summary>/// 必需的设计器变量。/// </summary>private System.ComponentModel.Container components = null;public frmreboot(){//// Windows 窗体设计器支持所必需的//InitializeComponent();//// TODO: 在 InitializeComponent 调用后添加任何构造函数代码//}/// <summary>/// 清理所有正在使用的资源。/// </summary>protected override void Dispose( bool disposing ){if( disposing ){if (components != null) {components.Dispose();}}base.Dispose( disposing );}#region Windows Form Designer generated code/// <summary>/// 设计器支持所需的方法 - 不要使用代码编辑器修改/// 此方法的内容。/// </summary>private void InitializeComponent(){this.label1 = new System.Windows.Forms.Label();this.label2 = new System.Windows.Forms.Label();this.label3 = new System.Windows.Forms.Label();this.textBox1 = new System.Windows.Forms.TextBox();this.textBox2 = new System.Windows.Forms.TextBox();this.textBox3 = new System.Windows.Forms.TextBox();this.button1 = new System.Windows.Forms.Button();this.SuspendLayout();// // label1// this.label1.Location = new System.Drawing.Point(16, 56);this.label1.Name = "label1";this.label1.Size = new System.Drawing.Size(120, 23);this.label1.TabIndex = 0;this.label1.Text = "机器名称或IP地址:";// // label2// this.label2.Location = new System.Drawing.Point(16, 88);this.label2.Name = "label2";this.label2.Size = new System.Drawing.Size(112, 16);this.label2.TabIndex = 1;this.label2.Text = "管理者名称:";// // label3// this.label3.Location = new System.Drawing.Point(16, 120);this.label3.Name = "label3";this.label3.Size = new System.Drawing.Size(104, 16);this.label3.TabIndex = 2;this.label3.Text = "管理者密码:";// // textBox1// this.textBox1.Location = new System.Drawing.Point(144, 56);this.textBox1.Name = "textBox1";this.textBox1.Size = new System.Drawing.Size(208, 21);this.textBox1.TabIndex = 3;this.textBox1.Text = "192.168.0.25";this.textBox1.MouseHover += new System.EventHandler(this.textBox1_MouseHover);// // textBox2// this.textBox2.Location = new System.Drawing.Point(144, 88);this.textBox2.Name = "textBox2";this.textBox2.Size = new System.Drawing.Size(208, 21);this.textBox2.TabIndex = 4;this.textBox2.Text = "administrator";// // textBox3// this.textBox3.Location = new System.Drawing.Point(144, 120);this.textBox3.Name = "textBox3";this.textBox3.PasswordChar = '#';this.textBox3.Size = new System.Drawing.Size(208, 21);this.textBox3.TabIndex = 5;this.textBox3.Text = "7751688mzh";this.textBox3.KeyDown += new System.Windows.Forms.KeyEventHandler(this.textBox3_KeyDown);// // button1// this.button1.Location = new System.Drawing.Point(104, 200);this.button1.Name = "button1";this.button1.Size = new System.Drawing.Size(152, 48);this.button1.TabIndex = 6;this.button1.Text = "重新启动远程计算机";this.button1.Click += new System.EventHandler(this.button1_Click);// // frmreboot// this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);this.ClientSize = new System.Drawing.Size(384, 301);this.Controls.AddRange(new System.Windows.Forms.Control[] { this.button1, this.textBox3, this.textBox2, this.textBox1, this.label3, this.label2, this.label1});this.MaximizeBox = false;this.Name = "frmreboot";this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;this.Text = "重启远程计算机";this.ResumeLayout(false);}#endregion/// <summary>/// 应用程序的主入口点。/// </summary>[STAThread]static void Main() {Application.Run(new frmreboot());}private void button1_Click(object sender, System.EventArgs e){ConnectionOptions options = new ConnectionOptions ( ) ;options.Username = textBox2.Text ;options.Password = textBox3.Text ;ManagementScope scope = new ManagementScope( "\\\\" + textBox1.Text + "\\root\\cimv2", options ) ;try {//用给定管理者用户名和口令连接远程的计算机scope.Connect ( ) ;System.Management.ObjectQuery oq = new System.Management.ObjectQuery ( "SELECT * FROM Win32_OperatingSystem" ) ;ManagementObjectSearcher query1 = new ManagementObjectSearcher ( scope , oq ) ;//得到WMI控制ManagementObjectCollection queryCollection1 = query1.Get ( ) ;foreach ( ManagementObject mo in queryCollection1 ){string [ ] ss= { "" } ;//重启远程计算机mo.InvokeMethod ( "Reboot" , ss ) ;}}//报错catch ( Exception ee ) {MessageBox.Show ( "连接" + textBox1.Text + "出错,出错信息为:" + ee.Message ) ;}}private void textBox1_MouseHover(object sender, System.EventArgs e){textBox1.SelectAll();//textBox1.Text="asdf";}private void textBox3_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e){}}}================================================================CSDN 论坛助手 Ver 1.0 B0402提供下载。 改进了很多,功能完备!★ 浏览帖子速度极快![建议系统使用ie5.5以上]。 ★ 多种帖子实现界面。 ★ 保存帖子到本地[html格式]★ 监视您关注帖子的回复更新。★ 可以直接发贴、回复帖子★ 采用XML接口,可以一次性显示4页帖子,同时支持自定义每次显示帖子数量。可以浏览历史记录! ★ 支持在线检测程序升级情况,可及时获得程序更新的信息。★★ 签名 ● 可以在您的每个帖子的后面自动加上一个自己设计的签名哟。Http://www.ChinaOK.net/csdn/csdn.zipHttp://www.ChinaOK.net/csdn/csdn.rar nt以上的都有WMI的,检查一下,看看你有没有安装或开启这项服务 c#程序中使用 Adobe reader 关闭时错误 只运行一个程序实例 问一下物流软件用C#开发还是用VC++开发好? 高分求教:结构体中如何初始化数组 求一数据处理解决方案 一个非常,非常,非常,非常奇怪的问题,我快要疯了.(一个关于access中插入数据的问题) imagelist索引超出界限 谁能说说写一个软件对网上的企业进行检索的思路? 如何用正则表达式获取 图片转换成PDF怎么写??(急急急) 谁有,C#开发软件规范,谢谢 请问windows的msmq(消息队列服务)可以用在什么地方啊?
using System ;
using System.Drawing ;
using System.Collections ;
using System.ComponentModel ;
using System.Windows.Forms ;
using System.Data ;
using System.Management;namespace rebootremote
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class frmreboot : System.Windows.Forms.Form
{
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.TextBox textBox2;
private System.Windows.Forms.TextBox textBox3;
private System.Windows.Forms.Button button1;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;public frmreboot()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}#region Windows Form Designer generated code
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.textBox1 = new System.Windows.Forms.TextBox();
this.textBox2 = new System.Windows.Forms.TextBox();
this.textBox3 = new System.Windows.Forms.TextBox();
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// label1
//
this.label1.Location = new System.Drawing.Point(16, 56);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(120, 23);
this.label1.TabIndex = 0;
this.label1.Text = "机器名称或IP地址:";
//
// label2
//
this.label2.Location = new System.Drawing.Point(16, 88);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(112, 16);
this.label2.TabIndex = 1;
this.label2.Text = "管理者名称:";
//
// label3
//
this.label3.Location = new System.Drawing.Point(16, 120);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(104, 16);
this.label3.TabIndex = 2;
this.label3.Text = "管理者密码:";
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(144, 56);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(208, 21);
this.textBox1.TabIndex = 3;
this.textBox1.Text = "192.168.0.25";
this.textBox1.MouseHover += new System.EventHandler(this.textBox1_MouseHover);
//
// textBox2
//
this.textBox2.Location = new System.Drawing.Point(144, 88);
this.textBox2.Name = "textBox2";
this.textBox2.Size = new System.Drawing.Size(208, 21);
this.textBox2.TabIndex = 4;
this.textBox2.Text = "administrator";
//
// textBox3
//
this.textBox3.Location = new System.Drawing.Point(144, 120);
this.textBox3.Name = "textBox3";
this.textBox3.PasswordChar = '#';
this.textBox3.Size = new System.Drawing.Size(208, 21);
this.textBox3.TabIndex = 5;
this.textBox3.Text = "7751688mzh";
this.textBox3.KeyDown += new System.Windows.Forms.KeyEventHandler(this.textBox3_KeyDown);
//
// button1
//
this.button1.Location = new System.Drawing.Point(104, 200);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(152, 48);
this.button1.TabIndex = 6;
this.button1.Text = "重新启动远程计算机";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// frmreboot
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(384, 301);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.button1,
this.textBox3,
this.textBox2,
this.textBox1,
this.label3,
this.label2,
this.label1});
this.MaximizeBox = false;
this.Name = "frmreboot";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "重启远程计算机";
this.ResumeLayout(false);}
#endregion/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new frmreboot());
}private void button1_Click(object sender, System.EventArgs e)
{
ConnectionOptions options = new ConnectionOptions ( ) ;
options.Username = textBox2.Text ;
options.Password = textBox3.Text ;
ManagementScope scope = new ManagementScope( "\\\\" + textBox1.Text + "\\root\\cimv2", options ) ;
try
{
//用给定管理者用户名和口令连接远程的计算机
scope.Connect ( ) ;
System.Management.ObjectQuery oq = new System.Management.ObjectQuery ( "SELECT * FROM Win32_OperatingSystem" ) ;
ManagementObjectSearcher query1 = new ManagementObjectSearcher ( scope , oq ) ;
//得到WMI控制
ManagementObjectCollection queryCollection1 = query1.Get ( ) ;
foreach ( ManagementObject mo in queryCollection1 )
{
string [ ] ss= { "" } ;
//重启远程计算机
mo.InvokeMethod ( "Reboot" , ss ) ;
}
}
//报错
catch ( Exception ee )
{
MessageBox.Show ( "连接" + textBox1.Text + "出错,出错信息为:" + ee.Message ) ;
}
}private void textBox1_MouseHover(object sender, System.EventArgs e)
{
textBox1.SelectAll();
//textBox1.Text="asdf";
}private void textBox3_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{}
}
}================================================================CSDN 论坛助手 Ver 1.0 B0402提供下载。 改进了很多,功能完备!★ 浏览帖子速度极快![建议系统使用ie5.5以上]。 ★ 多种帖子实现界面。
★ 保存帖子到本地[html格式]★ 监视您关注帖子的回复更新。
★ 可以直接发贴、回复帖子★ 采用XML接口,可以一次性显示4页帖子,同时支持自定义每次显示帖子数量。可以浏览历史记录!
★ 支持在线检测程序升级情况,可及时获得程序更新的信息。★★ 签名 ●
可以在您的每个帖子的后面自动加上一个自己设计的签名哟。Http://www.ChinaOK.net/csdn/csdn.zip
Http://www.ChinaOK.net/csdn/csdn.rar