基本信息
源码名称:C#实现获取并操作(启动、暂停、重启、停止)某台电脑 Windows 服务
源码大小:0.03M
文件格式:.zip
开发语言:C#
更新时间:2012-12-15
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 2 元×
微信扫码支付:2 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
C#实现获取并操作某台电脑 的所有Windows 服务,
实现的功能有:选中某一个服务,然后对其进行 启动服务、暂停服务、停止服务、重启服务等操作
获取服务代码:
private void GetServices_Button_Click(object sender, System.EventArgs e) { this.listBox1.Items.Clear(); if ( this.textBox1.Text.Equals("") ) { svcs=ServiceController.GetServices(); this.label2.Text="Services on then local machine"; } else { try { svcs=ServiceController.GetServices(this.textBox1.Text); this.textBox1.Text=""; return; } catch { MessageBox.Show("Unable to fine the computer!"); this.textBox1.Text=""; return; } } svcs_enum=svcs.GetEnumerator(); System.ServiceProcess.ServiceController sc; while(svcs_enum.MoveNext()) { sc=(ServiceController)svcs_enum.Current; this.listBox1.Items.Add(sc.ServiceName); } }
服务操作代码:
ServiceController sc; sc=(ServiceController)svcs.GetValue(this.listBox1.SelectedIndex); enable_disable_MenuItems(sc); try { sc.Stop(); sc.WaitForStatus(ServiceControllerStatus.Stopped); MessageBox.Show("Service " sc.ServiceName " stopped on " sc.MachineName " !"); } catch { MessageBox.Show("Unable to stop " sc.ServiceName " service!"); }
ServiceController sc; sc=(ServiceController)svcs.GetValue(this.listBox1.SelectedIndex); enable_disable_MenuItems(sc); try { sc.Pause(); sc.WaitForStatus(ServiceControllerStatus.Paused); MessageBox.Show("Service " sc.ServiceName " paused on " sc.MachineName " !"); } catch { MessageBox.Show("Unable to pause " sc.ServiceName " service!"); }