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 = "administrator";
                        //远程计算机用户名称
                        op.Password = "12345";   
                        //远程计算机用户密码
                        //设置操作管理范围
                        ManagementScope scope = new ManagementScope("\\\\" + "121.35.174.154" + "\\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为重新启动
                        }
                    }
                }
            }

  • 相关阅读:
    hive 修复分区、添加二级分区
    hive sql 查询一张表的数据不在另一张表中
    shell 命令 bc linux下的计算器
    shell 命令 grep -v
    shell 命令 -- 漂亮的资源查看命令 htop
    shell 命令 --ps aux | grep
    presto调研和json解析函数的使用
    shell wc -l
    hive 动态分区与混合分区
    ThreadLocal原理分析与使用场景(转)
  • 原文地址:https://www.cnblogs.com/ymyglhb/p/1265146.html
Copyright © 2011-2022 走看看