无法从服务执行程序

发布于 2024-08-02 08:57:48 字数 249 浏览 16 评论 0原文

我有一个 Windows 服务,我想定期执行一个外部程序。我目前正在按照通常的方式执行此操作,

Process program = Process.Start(@"C:\mpewatch\db_parameters\DBParameters.exe");

但这似乎不起作用。我从一个单独的线程执行此操作,该线程在我的服务的 OnStart 处理程序中启动。这有什么概念上的问题吗?难道不能从这样的服务执行外部程序吗?

I have a Windows service which I want to periodically execute an external program. I'm currently doing this the usual way

Process program = Process.Start(@"C:\mpewatch\db_parameters\DBParameters.exe");

This doesn't seem to be working. I'm executing this from a separate thread which is started in my service's OnStart handler. Is there any conceptual problem with this? Is it not possible to execute external programs from a service like this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

茶色山野 2024-08-09 08:57:48

可以从服务执行外部程序,但存在安全问题。例如,您的服务可能在没有外部程序所在文件夹的读取访问权限的帐户下运行,即使您的交互式帐户确实具有该访问权限。

出于测试目的,请尝试将服务配置为在您的交互式帐户下运行。如果程序按预期被调用,则原始帐户的问题在于它没有足够的权限来运行该程序。

You can execute external programs from a service, but there are security issues. For example, your service may be running under an account which does not have read access to the folder where the external program resides, even if your interactive account does have that access.

For test purposes, try to configure the service to run under your interactive account. If the program is invoked as expected, then the problem with the original account is that it does not have sufficient privileges to run the program.

初吻给了烟 2024-08-09 08:57:48

你的问题没有指出操作系统。

在 Windows XP 上,您可以将 Windows 服务配置为与桌面交互,方法是打开服务控制面板,双击您的服务,选择“登录”选项卡,将服务配置为作为本地系统运行,然后选中该复选框。这非常简单。您可以尝试使用 Notepad.exe 之类的东西进行测试,看看是否可以正常工作。

然而,在 Vista(可能还有 Windows 7)上,您可能会不走运。我读到,Windows 服务与桌面交互的能力在 Vista 中已被删除。我忘记了术语是什么,但基本上服务将在“shell 0”中运行,而用户将占用“shell 1”。用户应用程序将能够使用 WCF 等技术与服务进行通信,反之亦然,但服务将无法直接与桌面进行通信。例如,弹出的任何错误框都必须通过交换到“shell 0”来处理。再说一次,这是基于我几个月前读过的东西,我没有再看过它。对于我来说,我已经将 Windows 服务构建为通过前端应用程序使用 WCF 进行配置。

很抱歉,我没有给您的链接,但如果您的服务最终必须迁移到较新的操作系统(或者您已经在那里),则需要检查这一点。

Your question didn't indicate the operating system.

On Windows XP, you can configure your Windows service to interact with the desktop by opening the service control panel, double-clicking your service, selecting the Log On tab, configuring the service to run as local system, and checking the checkbox. It's pretty straightforward. You might try testing with something like Notepad.exe just to see if you can get it working.

On Vista (and presumably Windows 7), however, you may be out of luck. I have read that the ability for Windows services to interact with the desktop has been removed in Vista. I forget what the terminology is, but basically services will run in "shell 0," whereas users will occupy "shell 1". User applications will be able to communicate with services and vice versa using technology like WCF, but services will not be able to communicate directly with the desktop. For example, any error boxes that pop up will have to be dealt with by swapping to "shell 0." Again, this is based on something I read a few months ago, and I haven't gone looking at it again. For me, I've structured my Windows service to be configured using WCF via a front-end app.

I'm sorry I don't have a link for you, but if your service will eventually have to migrate to a newer OS (or you are already there), this is something to check on.

离线来电— 2024-08-09 08:57:48

Windows 服务的另一个重要考虑因素是没有 GUI。从技术上讲,有一个选项允许服务与本地 GUI 交互,但您不会看到它。这是由于服务以本地系统用户身份运行所致。

在服务中,任何模式对话框(确定、取消等)都被视为错误。

Another critical consideration with Windows Services is that there is no GUI. Technically, there is an option to allow the service to interact with a local GUI, but you will not see it. This is due to services running as the Local System user.

Within a service, any modal dialog box (OK, Cancel, etc) is considered an error.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文