3 回答

TA貢獻(xiàn)1790條經(jīng)驗(yàn) 獲得超9個(gè)贊
好的,這是真正為我工作的東西,它已經(jīng)在具有不同操作系統(tǒng)(Vista,XP,Win2k,Win2003服務(wù)器)的多臺(tái)計(jì)算機(jī)上進(jìn)行了測(cè)試。
該代碼已從此處獲取,因此無(wú)論誰(shuí)編寫(xiě)此代碼都應(yīng)歸功于此。
將dll或源文件添加到項(xiàng)目后,請(qǐng)確保添加ServiceTools命名空間,然后您可以訪問(wèn)一些非常方便的功能,例如...
//Installs and starts the service
ServiceInstaller.InstallAndStart("MyServiceName", "MyServiceDisplayName", "C:\\PathToServiceFile.exe");
//Removes the service
ServiceInstaller.Uninstall("MyServiceName");
//Checks the status of the service
ServiceInstaller.GetServiceStatus("MyServiceName");
//Starts the service
ServiceInstaller.StartService("MyServiceName");
//Stops the service
ServiceInstaller.StopService("MyServiceName");
//Check if service is installed
ServiceInstaller.ServiceIsInstalled("MyServiceName");
- 3 回答
- 0 關(guān)注
- 681 瀏覽
添加回答
舉報(bào)