我想要一个正确的运行示例如何从Windows服务运行exe [英] I want an proper run example how to run exe from windows service

查看:112
本文介绍了我想要一个正确的运行示例如何从Windows服务运行exe的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要一个正确的runnable示例,其中的代码运行我的exe服务来自windows服务

当我从exe运行show的服务启动服务到任务管理器进程但是我想在运行时该服务显示申请表的弹出窗口



请举例说明vb是如此之好



$ b



波纹管代码运行但它在进程选项卡中显示了一个exe但我想在启动时直接运行该exe服务











谢谢提前



我尝试过:



I want the proper runnable example with code that runs my exe from the windows service
when I start the service from services that exe run show into the task manager process but I want to when I run that service it shows the pop-up of the application form

Please Example is in vb that's so good




the bellow code run but it shows an exe in processes tab but I want to run that exe directly when I start the services





thanks in advance

What I have tried:

public partial class Service1 : ServiceBase
   {
       public Service1()
       {
           InitializeComponent();
       }

       protected override void OnStart(string[] args)
       {
           BackgroundWorker bw = new BackgroundWorker();
           bw.DoWork += new DoWorkEventHandler(bw_DoWork);
           bw.RunWorkerAsync();


       }

       protected override void OnStop()
       {
           Process p = new Process();
           p.Kill();
       }

       private void bw_DoWork(object sender, DoWorkEventArgs e)
       {
           Process p = new Process();
           p.StartInfo = new ProcessStartInfo("WindowsStartUpApp.exe");
           p.Start();
           p.WaitForExit();
           base.Stop();
       }
   }

推荐答案

这不是微不足道的,因为它真的,真的不是很好理念。服务根本不应该与用户交互,实际上不在用户帐户下运行,因此没有简单的机制来执行它。



有说,有可能: .net - 如何使用C#从Windows服务运行EXE程序? - 堆栈溢出 [ ^ ] - 但不要指望在未来版本的操作系统中工作(甚至在Win 10中,我还没有尝试过)。 />


如果您需要用户界面,则不应使用服务,您应该使用与服务交互的EXE。
That's not trivial, because it's really, really not a good idea. Services are not supposed to interact with the user at all, and in fact do not run under a user account, so there is no simple mechanism to do it.

Having said that, it is possible: .net - How can I run an EXE program from a Windows Service using C#? - Stack Overflow[^] - but don't expect that to work in future version of the OS (or even in Win 10, I haven't tried).

You should not be using a service if you require a user interface, you should be using an EXE that interacts with a service as necessary.


您可以尝试 TopShelf ,但不知道VB支持如何:使用Topshelf轻松创建Windows服务 - Visual Studio Magazine [ ^ ]
You could try TopShelf, don't know how the VB support is though: Create Windows Services Easily with Topshelf -- Visual Studio Magazine[^]


这篇关于我想要一个正确的运行示例如何从Windows服务运行exe的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆