zoukankan      html  css  js  c++  java
  • C#实现远程关机的小程序

    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 Ex18_11
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                //指定生成 WMI 连接所需的所有设置
                ConnectionOptions op = new ConnectionOptions();
                op.Username = "st6022";  //远程计算机用户名称
                op.Password = "administrator";   //远程计算机用户密码
                //设置操作管理范围
                ManagementScope scope = new ManagementScope("\\" + "10.10.10.89" + "\root\cimv2", op);
                scope.Connect();  //将此 ManagementScope 连接到实际的 WMI 范围。
                ObjectQuery oq = new ObjectQuery("SELECT * FROM Win32_OperatingSystem");
                ManagementObjectSearcher query = new ManagementObjectSearcher(scope, oq);
                //得到WMI控制 
                ManagementObjectCollection queryCollection = query.Get();
                foreach (ManagementObject obj in queryCollection)
                {
                    obj.InvokeMethod("ShutDown", null); //执行关闭远程计算机,reboot为重新启动
                }
            }
        }
    }
    using System;
    using System.Collections.Generic;
    using System.Windows.Forms;
    
    namespace Ex18_11
    {
        static class Program
        {
            /// <summary>
            /// 应用程序的主入口点。
            /// </summary>
            [STAThread]
            static void Main()
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new Form1());
            }
        }
    }
  • 相关阅读:
    字的传送
    mov 寄存器,段寄存器
    c语言中利用三维数组计算成绩总分数
    python中break语句
    c语言中求课程总分、平均分。学生总分及平均分
    python中assert语句
    python中random模块引入随机数
    python中实现列表的倒序排列
    c语言中求两个矩阵的乘积
    python的严格缩进可以避免else悬挂
  • 原文地址:https://www.cnblogs.com/xiaoqiaccp/p/3140444.html
Copyright © 2011-2022 走看看