ServiceController1
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using System.Collections; ///System.ServiceProcess.dll
using System.ServiceProcess;
//serviceController1 控件 namespace TEST
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private Hashtable ht = new Hashtable();
private string name;
private void Form1_Load(object sender, EventArgs e)
{
LoadServices();
} private void LoadServices()
{
ht.Clear();
this.lvServices.Items.Clear();
ServiceController[] sc = ServiceController.GetServices();
foreach (ServiceController item in sc)
{
ListViewItem lviServices = this.lvServices.Items.Add(item.DisplayName);
lviServices.SubItems.Add(item.ServiceName.ToString());
lviServices.SubItems.Add(item.Status.ToString());
lviServices.SubItems.Add(item.ServiceType.ToString());
//
ht.Add(item.DisplayName, item);
}
} private void SelectProcess()
{
if (this.lvServices.SelectedItems.Count != )
return;
name = this.lvServices.SelectedItems[].SubItems[].Text;
serviceController1 = ht[name] as ServiceController; // 如果当前状态是Stopped,就应该允许用户执行开始服务
this.btnStart.Enabled = (serviceController1.Status == ServiceControllerStatus.Stopped);
//如果当前状态不是Stopped并且系统允许停止服务,就应该允许用户执 行停止服务
this.btnStop.Enabled = (serviceController1.CanStop && (!(serviceController1.Status == ServiceControllerStatus.Stopped)));
//如果当前状态不是Paused并且系统允许暂停恢复服务,就应该允许用户执行暂停服务
this.btnPause.Enabled = (serviceController1.CanPauseAndContinue && (!(serviceController1.Status == ServiceControllerStatus.Paused)));
// 如果当前状态是Paused,就应该允许用户执行恢复服务
this.btnResume.Enabled = (serviceController1.Status == ServiceControllerStatus.Paused);
} private void btnStart_Click(object sender, EventArgs e)
{
this.serviceController1.Start();
LoadServices();
} private void btnPause_Click(object sender, EventArgs e)
{
this.serviceController1.Pause();
LoadServices();
} private void btnResume_Click(object sender, EventArgs e)
{
this.serviceController1.Continue(); ;
LoadServices();
} private void btnStop_Click(object sender, EventArgs e)
{
this.serviceController1.Stop();
LoadServices();
} private void lvServices_SelectedIndexChanged(object sender, EventArgs e)
{
SelectProcess();
}
}
}
ServiceController1的更多相关文章
- ServiceController组件控制计算机服务
private void Form1_Load(object sender, EventArgs e) { //下面的示例使用 ServiceController 类检查IIS服务是否已停止.如果该服 ...
- OpenFirewall
1.写一份json文件:将要添加防火墙例外的应用程序和端口写入到json文件中 2.打开防火墙,读取json文件添加例外 /// <summary> /// Firewall.xaml 的 ...
- C#启动或停止 计算机中“服务”
第一.要添加一个引用System.ServiceProcess 第二.要在程序中使用命名空间ServiceProcess 代码片段: using System.ServiceProcess; Serv ...
- 使用ServiceController组件控制计算机服务
实现效果: 知识运用: ServiceController组件的MachineName属性 //获取或设置服务所驻留的计算机名称 public string MachineName{get;set;} ...
- C#调用Resources.resx资源文件中的资源
使用到了.NET中的资源文件,也就是Resources.resx,于是就学会了如何调用资源文件中的资源.首先,资源文件可以从项目属性中的资源标签添加.比如,我添加一个图片,叫做aaa.png,添加入资 ...
随机推荐
- kuaisupaixu
#include<stdio.h> void quiksort(int a[],int low,int high) { int i = low; int j = high; ...
- pdo封装类
<?php //http://www.imavex.com/php-pdo-wrapper-class/ class db extends PDO { private $error; priva ...
- 64 位win 7或windows 8下的visual studio不能连接Oracle数据库调试网站的问题
在64 位win 7或windows 8系统下,visual studio直接F5运行网站调试,你会发现不能连接Oracle数据库,会报一个“ORA-06413: Connection not ope ...
- SQL2005的cte递归查询子树
;with cteas(select id,caption,parentid,1 Gen from skywfflow where parentid =0UNION ALL select a.id,a ...
- 低功耗蓝牙BLE [学习笔记]
手机设备会区分 "connecting" and "pairing" ,前者可以自动连接,后者则需要请求.BLE不再有pairing的麻烦,能直接连上目标设备, ...
- 阅读javaScript 的原型笔记
下面我们先看一个例子已经一张图. function Foo() { } Object.prototype.name = 'My Object'; Foo.prototype.name = 'Bar'; ...
- Nmap 網路診斷工具基本使用技巧與教學
Nmap 是一個開放原始碼的網路掃描與探測工具,可以讓網路管理者掃描整個子網域或主機的連接埠等,功能非常強大. Nmap(Network Mapper)是一個開放原始碼的網路檢測工具,它的功能非常強大 ...
- ajax处理回调函数,用ajax向后台发送数据
这是我的后台返回给前台的数据: 处理后台返回的数据有一下两种方式: function sethouse_housing_pattern(housing_pattern){ var str=[]; va ...
- Download InstallShield Limited Edition for Visual Studio 地址
http://learn.flexerasoftware.com/content/IS-EVAL-InstallShield-Limited-Edition-Visual-Studio?lang=10 ...
- iOS: 实现微信支付
一.介绍: 现在的消费越来越方便,直接带个手机用各种三方的支付平台进行支付就行,例如微信.支付宝.现在正好我所做的项目中用到了微信支付,今天就来整理一下. 二.准备: 1.去微信官方开发者平台注册开发 ...