亚洲喷奶水中文字幕电影,日本aⅴ高清一区二区三区,欧美亚洲日本国产,欧美日韩亚洲中文字幕

<legend id="flx4p"><abbr id="flx4p"><thead id="flx4p"></thead></abbr></legend>

<mark id="flx4p"><thead id="flx4p"></thead></mark>

      我要投稿 投訴建議

      C#實現(xiàn)遠程重啟計算機的方法

      時間:2021-04-03 14:47:59 計算機等級 我要投稿

      C#實現(xiàn)遠程重啟計算機的方法

        如果叫你實現(xiàn)遠程啟動別人的計算機,你首先想到的可能是先做一個在遠程計算機上面運行客戶端程序,然后在本地計算機上面再做一個服務(wù)器端程序,通過這二個程序直接的通訊實現(xiàn)重啟遠程計算機。這當然是一個方法。但這未免有點麻煩。如果現(xiàn)在只告訴你遠程計算機的管理者的登陸帳號,而并不允許你在遠程的計算機上面運行一個所謂的客戶端程序,讓你通過程序來完成重啟遠程計算機。不知道你是否感覺有些困難了。其實按照上面的這些條件實現(xiàn)重啟遠程計算機,利用C#可以比較方便的完成。下面就來介紹一下具體的實現(xiàn)方法。

        一.C#重啟遠程計算機的一些理論知識:

        C#實現(xiàn)啟動遠程計算機的原理是"視窗管理規(guī)范"。就是所謂的"WMI"(WindowsManagementInstrumentation)。Windows管理規(guī)范(WMI)支持通過Internet管理系統(tǒng)的結(jié)構(gòu)。通過提供管理環(huán)境的一致觀察,WMI為用戶提供通用訪問管理信息。該管理的.一致性使您能夠管理整個系統(tǒng),而不只是組件。從MicrosoftMSDN上,您可以獲得有關(guān)WMI軟件開發(fā)工具包(SDK)的詳細信息。

        WMI(Windows管理規(guī)范)支持有限的安全格式,允許用戶在本地計算機或遠程計算機上連接WMI之前要驗證每個用戶。這種安全性是操作系統(tǒng)已有的安全頂端的另一層。WMI不覆蓋或破壞由操作系統(tǒng)提供的任何現(xiàn)有的安全性。在默認情況下,管理員組的所有成員都可以完全控制它管理的計算機上的WMI服務(wù)。其他所有用戶在其本地計算機上只有讀取/寫入/執(zhí)行的權(quán)限?梢酝ㄟ^向被管理的計算機上的管理員組添加用戶,或者在WMI中授權(quán)用戶或組并設(shè)置權(quán)限級別來更改權(quán)限。訪問基于WMI名稱空間。在一般情況下,腳本程序的默認命名空間是"rootcimv2"。

        在WMI中有著許多足以令我們感覺驚奇的功能。重啟遠程計算機只是一個很小的功能。在程序中使用WMI可以編寫出許多遠程管理類型的應(yīng)用程序。由于在.NetFrameWorkSDK中提供了可以直接操作WMI的名稱空間,所以C#就可以利用在這些名稱空間中定義了的類來充分使用WMI控制給我們帶來的各種方便。

        二.程序設(shè)計和運行的環(huán)境設(shè)置:

       。1).windows2000Professional

       。2)..NetFrameWorkSDK

        (3).遠程計算機的管理者帳號

        以上這些不僅是本地計算機配置,還是遠程計算機的配置。

        三.實現(xiàn)重啟遠程計算機所使用到在.NetFrameWorkSDK用以操作WMI名稱空間和類:

        添加引用System.Management;

        在.NetFrameWorkSDK中用來操作WMI的名稱空間主要是"System.Management"。要實現(xiàn)重啟遠程計算機所使用到的類主要有六個:

        ."ConnectionOptions"類主要定義遠程計算機的管理員帳號;

        ."ManagementScope"主要是以給定的管理員帳號連接給定計算機名或者IP地址的計算機;

        ."ObjectQuery"類功能是定義對遠程計算機要實現(xiàn)那些地遠程操作;

        ."ManagementObjectSearcher"類從已經(jīng)完成遠程連接的計算機中,得到有那些WMI操作;

        ."ManagementObjectCollection"類存放得到WMI操作;

        ."ManagementObject"類調(diào)用遠程計算機可進行WMI操作。

        在本文介紹的操作就是重啟操作。

        四.C#重啟遠程計算機的重要步驟和實現(xiàn)方法:

       。1).連接遠程計算機:

        按照下列語句可以實現(xiàn)連接遠程計算機:

        ConnectionOptionsoptions=newConnectionOptions();

        options.Username="管理者帳號用戶名";

        options.Password="管理者帳號口令";

        ManagementScopescope=newManagementScope(""+"遠程計算機名或IP地址"+"rootcimv2",options);

        //用給定管理者用戶名和口令連接遠程的計算機

        scope.Connect();

        (2).得到在遠程計算機中可以進行WMI控制:

        System.Management.ObjectQueryoq=newSystem.Management.ObjectQuery("SELECT*FROMWin32_OperatingSystem");

        ManagementObjectSearcherquery1=newManagementObjectSearcher(scope,oq);

        //得到WMI控制

        ManagementObjectCollectionqueryCollection1=query1.Get();

       。3).調(diào)用WMI控制,實現(xiàn)重啟遠程計算機:

        foreach(ManagementObjectmoinqueryCollection1)

        {

        string[]ss={""};

        //重啟遠程計算機

        mo.InvokeMethod("Reboot",ss);

        }

        五.C#實現(xiàn)重啟遠程計算機的源程序代碼(boot.cs)和執(zhí)行界面:

        在了解了C#實現(xiàn)重啟遠程計算機的這些重要步驟后,就可以從容的得到重啟遠程計算機的完整代碼,具體如下:

        usingSystem;

        usingSystem.Drawing;

        usingSystem.Collections;

        usingSystem.ComponentModel;

        usingSystem.Windows.Forms;

        usingSystem.Data;

        usingSystem.Management;

        namespaceReStartboot

        {

        ///


        ///Form1的摘要說明。

        ///

        publicclassForm1:System.Windows.Forms.Form

        {

        privateSystem.Drawing.Printing.PrintDocumentprintDocument1;

        privateSystem.Windows.Forms.Labellabel1;

        privateSystem.Windows.Forms.Labellabel2;

        privateSystem.Windows.Forms.Labellabel3;

        privateSystem.Windows.Forms.TextBoxtextBox1;

        privateSystem.Windows.Forms.TextBoxtextBox2;

        privateSystem.Windows.Forms.TextBoxtextBox3;

        privateSystem.Windows.Forms.Buttonbutton1;

        ///


        ///必需的設(shè)計器變量。

        ///

        privateSystem.ComponentModel.Containercomponents=null;

        publicForm1()

        {

        //

        //Windows窗體設(shè)計器支持所必需的

        //

        InitializeComponent();

        //

        //TODO:在InitializeComponent調(diào)用后添加任何構(gòu)造函數(shù)代碼

        //

        }

        ///


        ///清理所有正在使用的資源。

        ///

        protectedoverridevoidDispose(booldisposing)

        {

        if(disposing)

        {

        if(components!=null)

        {

        components.Dispose();

        }

        }

        base.Dispose(disposing);

        }

        #regionWindowsFormDesignergeneratedcode

        ///


        ///設(shè)計器支持所需的方法-不要使用代碼編輯器修改

        ///此方法的內(nèi)容。

        ///

        privatevoidInitializeComponent()

        {

        this.printDocument1=newSystem.Drawing.Printing.PrintDocument();

        this.label1=newSystem.Windows.Forms.Label();

        this.label2=newSystem.Windows.Forms.Label();

        this.label3=newSystem.Windows.Forms.Label();

        this.textBox1=newSystem.Windows.Forms.TextBox();

        this.textBox2=newSystem.Windows.Forms.TextBox();

        this.textBox3=newSystem.Windows.Forms.TextBox();

        this.button1=newSystem.Windows.Forms.Button();

        this.SuspendLayout();

        //

        //label1

        //

        this.label1.Location=newSystem.Drawing.Point(16,32);

        this.label1.Name="label1";

        this.label1.Size=newSystem.Drawing.Size(120,23);

        this.label1.TabIndex=0;

        this.label1.Text="遠程計算機名或IP:";

        this.label1.TextAlign=System.Drawing.ContentAlignment.MiddleRight;

        //

        //label2

        //

        this.label2.Anchor=System.Windows.Forms.AnchorStyles.Top;

        this.label2.Location=newSystem.Drawing.Point(32,80);

        this.label2.Name="label2";

        this.label2.TabIndex=1;

        this.label2.Text="管理員名:";

        this.label2.TextAlign=System.Drawing.ContentAlignment.MiddleRight;

        //

        //label3

        //

        this.label3.Location=newSystem.Drawing.Point(32,128);

        this.label3.Name="label3";

        this.label3.TabIndex=2;

        this.label3.Text="密碼:";

        this.label3.TextAlign=System.Drawing.ContentAlignment.MiddleRight;

        //

        //textBox1

        //

        this.textBox1.Location=newSystem.Drawing.Point(136,32);

        this.textBox1.Name="textBox1";

        this.textBox1.Size=newSystem.Drawing.Size(152,21);

        this.textBox1.TabIndex=3;

        this.textBox1.Text="";

        //

        //textBox2

        //

        this.textBox2.Location=newSystem.Drawing.Point(136,80);

        this.textBox2.Name="textBox2";

        this.textBox2.Size=newSystem.Drawing.Size(152,21);

        this.textBox2.TabIndex=4;

        this.textBox2.Text="";

        //

        //textBox3

        //

        this.textBox3.Location=newSystem.Drawing.Point(136,128);

        this.textBox3.Name="textBox3";

        this.textBox3.Size=newSystem.Drawing.Size(152,21);

        this.textBox3.TabIndex=5;

        this.textBox3.Text="";

        //

        //button1

        //

        this.button1.Location=newSystem.Drawing.Point(104,168);

        this.button1.Name="button1";

        this.button1.Size=newSystem.Drawing.Size(120,23);

        this.button1.TabIndex=6;

        this.button1.Text="重啟遠程計算機";

        this.button1.Click+=newSystem.EventHandler(this.button1_Click);

        //

        //Form1

        //

        this.AutoScaleBaseSize=newSystem.Drawing.Size(6,14);

        this.ClientSize=newSystem.Drawing.Size(320,213);

        this.Controls.AddRange(newSystem.Windows.Forms.Control[]{this.label1});

        this.Name="Form1";

        this.Text="重啟遠程計算機";

        this.ResumeLayout(false);

        }

        #endregion

        ///


        ///應(yīng)用程序的主入口點。

        ///

        [STAThread]

        staticvoidMain()

        {

        Application.Run(newForm1());

        }

        privatevoidbutton1_Click(objectsender,System.EventArgse)

        {

        //定義連接遠程計算機的一些選項

        ConnectionOptionsoptions=newConnectionOptions();

        options.Username=textBox2.Text;

        options.Password=textBox3.Text;

        ManagementScopescope=newManagementScope(""+textBox1.Text+"rootcimv2",options);

        try

        {

        //用給定管理者用戶名和口令連接遠程的計算機

        scope.Connect();

        ObjectQueryoq=newObjectQuery("select*fromwin32_OperatingSystem");

        ManagementObjectSearcherquery1=newManagementObjectSearcher(scope,oq);

        ManagementObjectCollectionqueryCollection1=query1.Get();

        foreach(ManagementObjectmoinqueryCollection1)

        {

        string[]ss={""};

        mo.InvokeMethod("Reboot",ss);

        }

        }

        catch(Exceptioner)

        {

        MessageBox.Show("連接"+textBox1.Text+"出錯,出錯信息為:"+er.Message);

        }

        }

        }

        }

      【C#實現(xiàn)遠程重啟計算機的方法】相關(guān)文章:

      運行多臺遠程計算機的具體方法11-25

      探討計算機基礎(chǔ)課程遠程教學(xué)系統(tǒng)的設(shè)計及實現(xiàn)12-15

      計算機連接不到遠程桌面的解放方法11-23

      計算機技能:C#基礎(chǔ)之數(shù)據(jù)類型轉(zhuǎn)換12-08

      C#基礎(chǔ)的面試試題收集06-05

      關(guān)于關(guān)閉計算機的方法11-27

      計算機故障修復(fù)的方法11-20

      C#面試試題附答案06-21

      為什么電腦會藍屏重啟11-29