正在阅读:使用C#控制远程计算机的服务使用C#控制远程计算机的服务

2004-04-02 10:19 出处:CSDN 作者:zhzuo 责任编辑:sdq
通过vs.net 2003可以很快做出上面的窗体,下面列出了一些增加的代码:

using ZZ.Wmi;
namespace ZZForm
{
     public class Form1 : System.Windows.Forms.Form
     {
         //……
         private Win32ServiceManager serviceManager;
         public Form1()
         {
              InitializeComponent();
              this.serviceManager = null;
         }
         //……
         [STAThread]
         static void Main()
         {
              Application.Run(new Form1());
         }
         //修改服务状态
         private void buttonChangeState_Click(object sender, System.EventArgs e)
         {
              switch(((Button)sender).Text)
              {
                   case "启动":
                       string startRst = this.serviceManager.StartService(this.listViewService.SelectedItems[0].SubItems[0].Text);
                       if(startRst==null)
                            MessageBox.Show("操作成功,请点击获取刷新按钮刷新结果!");
                       else
                            MessageBox.Show(startRst);
                       break;
                   case "暂停":
                       string startPause = this.serviceManager.PauseService(this.listViewService.SelectedItems[0].SubItems[0].Text);
                       if(startPause==null)
                            MessageBox.Show("操作成功,请点击获取刷新按钮刷新结果!");
                       else
                            MessageBox.Show(startPause);
                       break;
                   case "继续":
                       string startResume = this.serviceManager.ResumeService(this.listViewService.SelectedItems[0].SubItems[0].Text);
                       if(startResume==null)
                            MessageBox.Show("操作成功,请点击获取刷新按钮刷新结果!");
                       else
                            MessageBox.Show(startResume);
                       break;
                   case "停止":
                       string startStop = this.serviceManager.StopService(this.listViewService.SelectedItems[0].SubItems[0].Text);
                       if(startStop==null)
                            MessageBox.Show("操作成功,请点击获取刷新按钮刷新结果!");
                       else
                            MessageBox.Show(startStop);
                       break;
              }
         }

察看评论详细内容 我要发表评论
作者笔名 简短内容 发表时间
:

键盘也能翻页,试试“← →”键

相关文章

关注我们

最新资讯离线随时看 聊天吐槽赢奖品