如何在vb.net中以编程方式安装窗口服务

时间:2013-04-03 10:16:48

标签: .net vb.net windows-services

如何以编程方式安装Windows服务?

我想点击注册按钮安装我的Windows服务&单击取消注册按钮卸载它。

1 个答案:

答案 0 :(得分: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");