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

我的VS解决方案中有3个项目。其中一个是Web应用程序,第二个是Windows服务,最后一个是我的Web应用程序的安装项目。

我想要的是在安装项目中完成Web应用程序的安装,在我自定义动作中尝试安装Windows服务的前提下,前提是我那时具有程序集的位置。


杨__羊羊
浏览 624回答 3
3回答

富国沪深

好的,这是真正为我工作的东西,它已经在具有不同操作系统(Vista,XP,Win2k,Win2003服务器)的多台计算机上进行了测试。该代码已从此处获取,因此无论谁编写此代码都应归功于此。将dll或源文件添加到项目后,请确保添加ServiceTools命名空间,然后您可以访问一些非常方便的功能,例如...//Installs and starts the serviceServiceInstaller.InstallAndStart("MyServiceName", "MyServiceDisplayName", "C:\\PathToServiceFile.exe");//Removes the serviceServiceInstaller.Uninstall("MyServiceName");//Checks the status of the serviceServiceInstaller.GetServiceStatus("MyServiceName");//Starts the serviceServiceInstaller.StartService("MyServiceName");//Stops the serviceServiceInstaller.StopService("MyServiceName");//Check if service is installedServiceInstaller.ServiceIsInstalled("MyServiceName");
打开App,查看更多内容
随时随地看视频慕课网APP