通过Windows Service启动进程 [英] Starting processes via Windows Service

查看:426
本文介绍了通过Windows Service启动进程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!

在访问我们的应用程序之前,我们需要启动一些流程.

一种方法是制作一个批处理文件,然后在Windows启动期间自动运行它.

我们更喜欢做的另一种方法是通过WindowsService启动这些进程,可以通过我们的应用程序界面启动和停止这些进程.

因此,问题是:
使用VS/C#中的"WindowsService"项目,我们可以在WindowsService的OnStart()方法内调用Process.Start()吗?在我们的代码中这样做不会启动预期的过程.我们在这里想念什么吗?

感谢您的宝贵时间.

Hi!

We have a requirement to start few processes before accessing our application.

One way to do this is to make a batch file and run it automatically during windows startup.

Another way, which we prefer doing, is to start these processes via WindowsService, which can be started and stopped via our application interface.

Question thus is:
Using "WindowsService" project in VS/C#, can we call Process.Start() inside the OnStart() method of a WindowsService? Doing so in our code does not start the intended process. Are we missing something here?

Thanks for your time.

推荐答案

完全错误的方法.最糟糕的方法是从服务启动用户模式应用程序.

如果您的服务已安装在计算机上并设置为启动自动",则它们将在Windows启动时启动.

如果手动设置它们,则可以在用户许可的情况下直接从您的应用程序中启动/停止它们.

在Windows 7上,您还可以设置触发器以启动服务.我根本没有研究过,因此您必须进行研究,但是您的应用程序应该能够通过触发器启动服务,而触发器无需用户权限即可.
Completely wrong approaches. About the worst way to do this is to start user-mode applications from a service.

If your services are installed on the machine and setup to start Automatic, then they''ll start when Windows starts.

If they are setup manually, then you can start/stop them right from your application, provided the users have the permissions to do so.

On Windows 7, you can also setup triggers to start services. I haven''t looked into this at all, so you''ll have to do the research, but your application should be able to start the services via a trigger, which should not need user permissions to do so.


您可能不了解Windows服务是什么.
让我们不要混淆不同的东西.开发某些可以作为服务或交互式应用程序启动的应用程序是很有可能的.例如,这实际上对于调试非常有用.我确实使用了这种方法,并享受它的强大功能.

问题是不同的.当您设法做到这一点时,就像有两个应用程序合而为一.即使它们共享一些代码(这是此类设计的主要目的),这实际上是两个不同的应用程序.如果通过System.Diagnostics.Process.Run运行这样的应用程序,则它不是Windows服务定义为.如果通过Service Controller运行它,则它不是交互式应用程序-定义为 .这两种模式永远不会同时运行.

一个有用的提示:请参阅属性System.Environment.UserInteractive.

—SA
You probably do not understand what a Windows Service is.
Let''s not mix up different things. It''s quite possible to develop some application which can start either as service or as an interactive application. This is actually very useful, for debugging, for example. I do use this approach and enjoy its robustness.

The problem is different. When you manage to do that, this is like having two application in one. Even it they share some code (which is the main purpose of such design), this is really two different application. If you run such application through System.Diagnostics.Process.Run, it is not a Windows Service by definition. If you run it via Service Controller, it is not an interactive application — by definition. These two modes never run at the same time.

One useful hint: see the property System.Environment.UserInteractive.

—SA


这篇关于通过Windows Service启动进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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