C#远程重启计算机
来源:互联网 发布:开源crm软件排名 编辑:程序博客网 时间:2024/06/05 13:22
什么也不说了,直接看代码
using System;
using System.Collections.Generic;using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Management;
namespace 重启远程计算机
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
comboBox1.Items.Add("重新启动");
comboBox1.Items.Add("关闭计算机");
comboBox1.SelectedIndex = 0;
//comboBox1.Items.Add("注销");
}
private void button1_Click(object sender, 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();
ObjectQuery oq = new ObjectQuery("select * from win32_OperatingSystem");
ManagementObjectSearcher query1 = new ManagementObjectSearcher(scope, oq);
ManagementObjectCollection queryCollection1 = query1.Get();
foreach (ManagementObject mo in queryCollection1)
{
string[] ss = { "" };
if (comboBox1.Text == "重新启动")
{
mo.InvokeMethod("Reboot", ss);
}
if (comboBox1.Text == "关闭计算机")
{
mo.InvokeMethod("Shutdown", ss);
}
//if (comboBox1.Text == "注销")
//{
// mo.InvokeMethod("Logoff", ss);
//}
}
}
catch (Exception er)
{
MessageBox.Show("连接" + textBox1.Text + "出错,出错信息为:" + er.Message);
}
}
}
}
- C#远程重启计算机
- C#远程重启计算机(转)
- C#远程重启计算机(转)
- C#远程重启计算机/使用c#控制远程计算机的服务
- c# 重起远程计算机(载)
- C#重启计算机
- C#重启远程计算机
- C#重启远程计算机
- 重启远程计算机(WMI)
- 重启/关机远程计算机
- PowerShell 重启远程计算机
- 利用C#重启远程计算机
- 利用C#重启远程计算机
- 利用C#重启远程计算机
- C#重启远程计算机的代码
- 利用C#重启远程计算机
- 远程重启计算机(C#)
- 利用C#重启远程计算机
- bitblt()用法
- 15.理论知识:直线
- 创建uinavigationbar右侧的button
- 数据分析10大杯具
- 16.Checkpoint!: Adding checkpoints to the racing scenario by looking at the intersection of two line
- C#远程重启计算机
- BitSet 与 Byte Array 类型转化 转发
- 17. 首先我们获取曼哈顿距离:如何在一个网格里测量距离
- 一些偏的数据结构整理【整理+复习】
- 代码三要素——赢得面试官芳心
- 18.寻找你周围的道路:在设有障碍物的网格中寻路
- 19.绘制一条直线:在绘制直线时决定去填充哪些像素
- ASP.NET上传文件的三种基本方法
- 几道经典的嵌入式C语言笔试题