2013-04-03 72 views
0

如何以編程方式安裝Windows服務?如何以編程方式在vb.net中安裝窗口服務

我想點擊一個註冊按鈕來安裝我的Windows服務&通過點擊一個註冊按鈕來卸載它。

+0

只需使用Process類運行InstallUtil.exe。這通常是一個相當糟糕的主意,因爲這需要管理員權限和UAC提升。 –

回答

0

參考(在C#不過):

How to install a windows service programmatically in C#?

//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");