#C#Windows系统服务源代码Word下载.docx
《#C#Windows系统服务源代码Word下载.docx》由会员分享,可在线阅读,更多相关《#C#Windows系统服务源代码Word下载.docx(34页珍藏版)》请在冰豆网上搜索。
![#C#Windows系统服务源代码Word下载.docx](https://file1.bdocx.com/fileroot1/2022-11/24/6bb5619a-1b9b-445d-ad9d-c9deba6e4ec8/6bb5619a-1b9b-445d-ad9d-c9deba6e4ec81.gif)
usingSystem.Windows.Forms。
usingMicrosoft.Win32。
usingSystem.IO。
usingSystem.ServiceProcess。
usingSystem.Diagnostics。
3.刷新服务功能的实现
privatevoid刷新ToolStripMenuItem_Click(objectsender,EventArgse>
{
lstserver.Items.Clear(>
。
#region刷新服务
watch=System.ServiceProcess.ServiceController.GetServices(>
foreach(ServiceControllertempinwatch>
try
stringservepath="
"
ListViewItemlv=newListViewItem(temp.DisplayName.ToString(>
>
lv.SubItems.Add(temp.ServiceName.ToString(>
#region1.服务状态
if(temp.Status.ToString(>
=="
Stopped"
lv.SubItems.Add("
已停止"
}
elseif(temp.Status.ToString(>
Running"
正在运行"
else
已暂停"
#endregion
#region2.服务启动类型
RegistryKeyhklmrun1=Registry.LocalMachine。
RegistryKeyhklmrun2=hklmrun1.CreateSubKey(@"
system\currentcontrolset\services\"
+temp.ServiceName.ToString(>
stringregs=hklmrun2.GetValue("
start"
.ToString(>
if(regs=="
3"
手动"
elseif(regs=="
4"
已禁用"
2"
>
自动"
0"
未知"
catch
#region3.服务描述
RegistryKeyhklmrun2=hklmrun1.CreateSubKey(@"
Description"
lv.SubItems.Add(regs>
#region4.服务路径
servepath=hklmrun2.GetValue("
ImagePath"
lv.SubItems.Add(servepath>
#region5.服务厂商
stringfileinfo="
FileVersionInfofinfo=FileVersionInfo.GetVersionInfo(@servepath>
fileinfo=finfo.CompanyName。
lv.SubItems.Add(fileinfo>
if(fileinfo!
="
MicrosoftCorporation"
&
fileinfo!
="
lv.ForeColor=Color.Blue。
lstserver.Items.Add(lv>
lblservecount.Text="
当前服务:
+lstserver.Items.Count.ToString(>
+"
项"
4.显示已启动服务功能的实现
privatevoid显示已启动服务ToolStripMenuItem_Click(objectsender,EventArgse>
#regionforeach
stringserverrunning="
serverrunning=temp.Status.ToString(>
if(serverrunning=="
ListViewItemlv=newListViewItem(temp.DisplayName.ToString(>
RegistryKeyhklmrun2=hklmrun1.CreateSubKey(@"
||regs=="
&
fileinfo!
5.显示未启动服务功能的实现
privatevoid显示未启动服务ToolStripMenuItem_Click(objectsender,EventArgse>
if(serverrunning!
6.显示自动启动服务功能的实现
privatevoid显示自动启动服务ToolStripMenuItem_Click(objectsender,EventArgse>
RegistryKeyhklmrun11=Registry.LocalMachine。
RegistryKeyhklmrun21=hklmrun11.CreateSubKey(@"
stringserverrunning=hklmrun21.GetValue("
||serverrunning=="
ls