为什么窗体在 Windows 服务中失败 [英] Why do forms fail in Windows Services

查看:24
本文介绍了为什么窗体在 Windows 服务中失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道Window的服务没有桌面,不能直接访问用户的任何桌面(事实上,它们可以在没有桌面加载的情况下运行).为什么在 Window 的服务中启动表单会导致错误?

I understand that Window's Services have no desktop, and can't access any of the user's desktops directly (indeed, they can run when there is no desktop loaded). Why is it though that launching a form in a Window's Service causes an error?

推荐答案

您必须启用一个设置,才能允许您的 Windows 服务直接访问某些文件夹(如桌面)或显示表单(包括 MessageBox 弹出窗口):允许服务与桌面交互"

There's a setting you must enable in order to allow your Windows Service to access certain folders directly (like desktop) or show forms (including MessageBox pop-ups): "Allow service to interact with desktop"

要查看此内容,请右键单击我的电脑 => 管理 => 服务和应用程序 => 服务.双击服务以访问其属性.在登录"选项卡上有一个此设置的复选框.

To see this, right click on My Computer => Manage => Services and Applications => Services. Double-click on a service to access its properties. On the "Log On" tab there is a checkbox for this setting.

这里是一篇关于如何在 C# 中以编程方式设置它的文章

Here is an article for how to set it programmatically in C#

正如 Stephen Martin 在评论中指出的那样:这只是对 Windows 的 Vista 之前版本的有效建议.

As Stephen Martin points out in the comments: this is only valid advice for pre-Vista versions of Windows.

这篇关于为什么窗体在 Windows 服务中失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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