C#實(shí)現(xiàn)操作windows系統(tǒng)服務(wù)(service)的方法
更新時間:2015年04月28日 11:35:59 作者:igoo
這篇文章主要介紹了C#實(shí)現(xiàn)操作windows系統(tǒng)服務(wù)(service)的方法,可實(shí)現(xiàn)系統(tǒng)服務(wù)的啟動和停止功能,非常具有實(shí)用價值,需要的朋友可以參考下
本文實(shí)例講述了C#實(shí)現(xiàn)操作windows系統(tǒng)服務(wù)(service)的方法。分享給大家供大家參考。具體如下:
這段C#代碼可以控制啟動和停止系統(tǒng)服務(wù)
/// <summary>
/// 停止服務(wù)
/// </summary>
private bool StopService(string StopServiceName)
{
ServiceController service = new ServiceController(StopServiceName);
try
{
service.Stop();
service.WaitForStatus(ServiceControllerStatus.Stopped);
}
catch(Exception)
{
return false;
}
return true;
}
/// <summary>
/// 開啟服務(wù)
/// </summary>
private bool StartService(string StartServiceName)
{
ServiceController service = new ServiceController(StartServiceName);
try
{
service.Start();
service.WaitForStatus(ServiceControllerStatus.Running);
}
catch (Exception)
{
return false;
}
return true;
}
希望本文所述對大家的C#程序設(shè)計有所幫助。
您可能感興趣的文章:
- C#實(shí)現(xiàn)Windows服務(wù)測試與調(diào)試
- C#創(chuàng)建Windows服務(wù)與服務(wù)的安裝、卸載
- C#創(chuàng)建控制Windows服務(wù)
- C#創(chuàng)建Windows服務(wù)的實(shí)現(xiàn)方法
- C#對Windows服務(wù)組的啟動與停止操作
- C#使用windows服務(wù)開啟應(yīng)用程序的方法
- c#創(chuàng)建windows服務(wù)入門教程實(shí)例
- c#創(chuàng)建windows服務(wù)(Windows Services)詳細(xì)步驟
- C#編寫Windows服務(wù)實(shí)例代碼
- C#操作Windows服務(wù)類System.ServiceProcess.ServiceBase
相關(guān)文章
Unity實(shí)現(xiàn)鼠標(biāo)雙擊與長按的檢測
這篇文章主要為大家詳細(xì)介紹了Unity實(shí)現(xiàn)鼠標(biāo)雙擊與長按的檢測,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下2020-02-02
在C#中調(diào)用Python代碼的兩種實(shí)現(xiàn)方式
這篇文章主要介紹了在C#中調(diào)用Python代碼的兩種實(shí)現(xiàn)方式,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2025-03-03
C#將Excel中的數(shù)據(jù)轉(zhuǎn)換成DataSet
這篇文章主要介紹了C#將Excel中的數(shù)據(jù)轉(zhuǎn)換成DataSet的方法,非常簡單實(shí)用,從本人項(xiàng)目中提取出來的,推薦給大家,希望對大家學(xué)習(xí)C#能夠有所幫助。2015-03-03

