0

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

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

4

1 回答 1

0

参考(但是在C#中):

如何在 C# 中以编程方式安装 Windows 服务?

//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");
于 2013-04-03T13:42:16.213 回答