using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Management;
namespace RebootApplication
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : 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 txtip;
private System.Windows.Forms.TextBox txtAccount;
private System.Windows.Forms.TextBox txtPwd;
private System.Windows.Forms.Button btnReboot;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗体设计器生成的代码
/// <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.txtip = new System.Windows.Forms.TextBox();
this.txtAccount = new System.Windows.Forms.TextBox();
this.txtPwd = new System.Windows.Forms.TextBox();
this.btnReboot = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// label1
//
this.label1.Location = new System.Drawing.Point(56, 56);
this.label1.Name = "label1";
this.label1.TabIndex = 0;
this.label1.Text = "Machine Name/IP";
//
// label2
//
this.label2.Location = new System.Drawing.Point(56, 136);
this.label2.Name = "label2";
this.label2.TabIndex = 1;
this.label2.Text = "Password";
//
// label3
//
this.label3.Location = new System.Drawing.Point(56, 96);
this.label3.Name = "label3";
this.label3.TabIndex = 2;
this.label3.Text = "Account";
//
// txtip
//
this.txtip.Location = new System.Drawing.Point(176, 56);
this.txtip.Name = "txtip";
this.txtip.Size = new System.Drawing.Size(120, 21);
this.txtip.TabIndex = 3;
this.txtip.Text = "";
//
// txtAccount
//
this.txtAccount.Location = new System.Drawing.Point(176, 96);
this.txtAccount.Name = "txtAccount";
this.txtAccount.Size = new System.Drawing.Size(120, 21);
this.txtAccount.TabIndex = 4;
this.txtAccount.Text = "";
//
// txtPwd
//
this.txtPwd.Location = new System.Drawing.Point(176, 136);
this.txtPwd.Name = "txtPwd";
this.txtPwd.Size = new System.Drawing.Size(120, 21);
this.txtPwd.TabIndex = 5;
this.txtPwd.Text = "";
//
// btnReboot
//
this.btnReboot.Location = new System.Drawing.Point(144, 176);
this.btnReboot.Name = "btnReboot";
this.btnReboot.Size = new System.Drawing.Size(72, 24);
this.btnReboot.TabIndex = 6;
this.btnReboot.Text = "Reboot";
this.btnReboot.Click += new System.EventHandler(this.btnReboot_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(464, 275);
this.Controls.Add(this.btnReboot);
this.Controls.Add(this.txtPwd);
this.Controls.Add(this.txtAccount);
this.Controls.Add(this.txtip);
this.Controls.Add(this.label3);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void Form1_Load(object sender, System.EventArgs e)
{
}
private void btnReboot_Click(object sender, System.EventArgs e)
{
ConnectionOptions option=new ConnectionOptions();
option.Username=txtAccount.Text;
option.Password=txtPwd.Text;
ManagementScope scope=new ManagementScope("\\\\"+this.txtip.Text+"\\root\\cimv2",option);
try
{
scope.Connect();
System.Management.ObjectQuery query=new ObjectQuery("select * from Win32_OperatingSystem");
System.Management.ManagementObjectSearcher searcher=new ManagementObjectSearcher(scope,query);
System.Management.ManagementObjectCollection moc=searcher.Get();
foreach (System.Management.ManagementObject mo in moc)
{
string[] s={""};
mo.InvokeMethod("reboot",s);
}
}
catch(Exception aa)
{
MessageBox.Show("Error occured! "+aa.Message);
}
}
}
}

浙公网安备 33010602011771号