2013-04-03 68 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");