在我的VS解决方案中,我有两个项目:一个windows服务和一个带有一个表单和两个按钮(install/uninstall和start/stop)的win应用程序。我关注了Matt Davis的教程
How to make a .NET Windows Service start right after the installation?
为了创建ProjectInstaller,现在我很困惑如何在点击按钮时实际启动安装,这是在另一个项目(win应用程序)中。感谢您的帮助。
发布于 2014-06-01 19:11:59
这是未经测试的,但如果您在win app中添加对System.Configuration.Install的引用。此程序集包含用于安装服务的中的所有代码。然后,从你的win应用程序中的代码中,你可以添加如下内容:
public void InstallService(string pathToAssembly)
{
System.Configuration.Install.ManagedInstallerClass.InstallHelper(new string[] { pathToAssembly });
}要使用它,您只需要知道从ServiceBase继承的服务的exe文件的路径。
发布于 2014-06-01 22:10:14
我的教程适合从命令行安装服务,而不是从其他应用程序安装。也就是说,我认为这样做很容易(尽管我还没有测试过它):
string pathToServiceExecutable = ...; // specify the full path to your service
System.Diagnostics.Process.Start(pathToServiceExecutable, "-install");https://stackoverflow.com/questions/23979102
复制相似问题