熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

c# 實現遠程關機功能

2013-11-13 10:28:19  來源: .NET編程 

  代碼如下

    using System;
        using SystemCollectionsGeneric;
        using SystemComponentModel;

  using SystemData;
        using SystemDrawing;
        using SystemText;
        using SystemWindowsForms;
        using SystemManagement;
        namespace Ex_
        {
            public partial class Form : Form
            {
                public Form()
                {
                    InitializeComponent();
                }
                private void button_Click(object sender EventArgs e)
                {
                    //指定生成 WMI 連接所需的所有設置
                    ConnectionOptions op = new ConnectionOptions();
                    opUsername = administrator;
                    //遠程計算機用戶名稱
                    opPassword = ;   
                    //遠程計算機用戶密碼
                    //設置操作管理范圍
                    ManagementScope scope = new ManagementScope(\\\\ + + \\root\\cimv op);
                    scopeConnect();
                    //將此 ManagementScope 連接到實際的 WMI 范圍
                    ObjectQuery oq = new ObjectQuery(SELECT * FROM Win_OperatingSystem);
                    ManagementObjectSearcher query = new ManagementObjectSearcher(scope oq);
                    //得到WMI控制
                    ManagementObjectCollection queryCollection = queryGet();
                    foreach (ManagementObject obj in queryCollection)
                    {
                        objInvokeMethod(ShutDown null); //執行關閉遠程計算機reboot為重新啟動
                    }
                }
            }
        }


From:http://tw.wingwit.com/Article/program/net/201311/13762.html
    推薦文章
    Copyright © 2005-2013 電腦知識網 Computer Knowledge   All rights reserved.