是否可以以编程方式运行Windows服务窗体Windows窗体应用程序? 我的意思是..在一个解决方案中,我有两个项目:服务和简单的Windows应用程序. 在应用程序中,我有三个按钮-开始",安装"和停止".我应该怎么办? 我必须从Windows服务生成exe文件吗?而且比以某种方式从应用程序运行它?我需要在解决方案中创建Windows Installer吗? 感谢您的帮助 我想构建一个客户端将以传统方式安装的程序-Simply Windows Forms应用程序.一个安装文件. And ..在此应用程序中将可以选择启动或停止Windows服务. 在Visual Studio中,我有一个想法,有两个项目-我想要一个安装文件.
Is it possible to run windows service form windows form application programmatically? I mean.. In one solution, I have two projects: Service, and simple windows app. In app i have three buttons - "Start", "Install" and "Stop". What should I do? I must generate exe file from Windows Service? And than somehow run it from app? I need to create Windows Installer in my solution? Thanks for your help edit: I would like to build a program that will be installed in the traditional manner by the client - Simply Windows Forms app. One setup file. And.. in this application will be option to start or stop a windows service. In Visual Studio I''ve got one soultion, with two projects - I want one setup file.
推荐答案您可以在一个可执行文件中全部完成.要传递安装参数,您将需要派生类System.ServiceProcess.ServiceProcessInstaller和System.ServiceProcess.ServiceInstaller.您只需要实现类的构造函数. 安装和卸载将由System.Configuration.Install.AssemblyInstaller完成.此类应使用实现基于ServiceProcessInstaller和ServiceInstaller的类的程序集;该实现将在您的程序集中自动找到(如果实现中存在错误,则将导致难以发现的故障).不过还算不错. 最后,启动/停止等由您创建的服务代码处理,该服务代码派生出类System.ServiceProcess.ServiceBase.触发此操作由服务控制器完成.要以编程方式执行此操作,应使用类System.ServiceProcess.ServiceController. 您需要对MSDN进行很好的阅读,以了解我在上面列出的类周围的主题,代码示例对此进行了很好的说明.这些信息很容易找到,很难理解工作流程以及在哪个过程中会发生什么. (Windows Service进程始终是一个单独的进程;它需要另一个进程来运行安装和Service Controller的一部分.)您可以像食谱一样使用所有这些程序,但是我建议您完全理解它;在这种情况下,您不会有任何问题. 您甚至可以像我一样尝试在一个应用程序中实现所有功能,但仍然需要至少在两个不同的进程中运行它:一个可以在Windows Service模式下工作,另一个必须是交互模式,可以是其他任何模式,例如UI,控制台或不可见的批处理模式应用程序. 重要!您的代码可以在运行时测试System.Environment.UserInteractive,以计算当前正在运行的代码是否以Windows Service运行.
是的,您可以做到. 此处: 启动,停止和重新启动Windows服务[C#] [ ^ ] C#中的Windows服务:从另一个应用程序控制您的服务(第6部分) [ ^ ] 试试吧! 更新: 很棒的文章,但是我需要先安装我的服务.那篇文章只向我展示了如何启动和停止服务. 来吧,努力.样本: 发送自动电子邮件警报的简单Windows服务 [ ^ ] MSDN:有关Windows服务的详细信息: Windows服务应用程序简介 [ ^ ] 我希望现在您不要说现在,我提供了Windows服务,我知道如何从C#应用程序中使用它,但如何安装它?" Yes, you can do it. Here: Start, Stop and Restart Windows Service [C#][^] Windows Services in C#: Controlling Your Service from Another Application (part 6)[^] Try! UPDATE: Great articles, but i need to install first my service. That articles show me only how to start and stop service. Come on man, make some effort. Sample: Simple Windows Service which sends auto Email alerts[^] MSDN: Details about Windows Service: Introduction to Windows Service Applications[^] I hope now you don''t say ''Now, I made Windows service, I know how to use it from a C# app but how to install it?''
更多推荐
如何以编程方式安装Windows Service
发布评论