[英]Alternative to “Allow service to interact with desktop”?
I have a windows service (C#) installed on a server that launches every 10 minutes an executable file (C#) to process some images from one directory to another. 我在服务器上安装了一个Windows服务(C#),它每10分钟启动一个可执行文件(C#),以处理从一个目录到另一个目录的一些图像。 No interaction is required with any user. 任何用户都不需要进行任何交互。 Nevertheless, since the executable file as an output window, to make the service run I have to enable the " Allow service to interact with desktop " checkbox which is considered as an insecure and bad practice . 尽管如此,由于可执行文件作为输出窗口,为了使服务运行,我必须启用“ 允许服务与桌面交互 ”复选框,这被认为是一种不安全和不良做法 。 How would I go about this problem? 我该如何解决这个问题? I like to have the executable separated from my windows service because 我喜欢将可执行文件与我的Windows服务分开,因为
EDIT: 编辑:
When the interaction with the desktop is not enabled, the console application does not get executed correctly and the following error appears inside the Windows Logs: 未启用与桌面的交互时,控制台应用程序无法正确执行,并且Windows日志中会出现以下错误:
Faulting application myapp.exe, version 1.0.0.0, time stamp 0x4b8304c3,
faulting module KERNEL32.dll, version 6.0.6002.18005, time stamp 0x49e03821,
exception code 0xc0000142, fault offset 0x00009eed, process id 0x10ec,
application start time 0x01cab736950a64b5.
Once the desktop interaction is enabled, application gets executed normally. 启用桌面交互后,应用程序将正常执行。
Any thoughts? 有什么想法吗?
Thanks a lot for your time. 非常感谢你的时间。
If you are using Vista and later and you don't really need any interaction with the user, but have an interactive exe to execute, the Session 0 isolation feature should help alleviate some of the concerns about the 'bad practice' on having a service interact with the desktop (which in Session 0 has no physical console). 如果您使用的是Vista及更高版本并且您实际上不需要与用户进行任何交互,但是要执行交互式exe,则会话0隔离功能应该有助于减轻对服务“不良做法”的一些担忧与桌面交互(在会话0中没有物理控制台)。
This Session 0 isolation would prevent unprivileged users from performing Shatter Attacks on your service as they get their interactive desktops in different sessions. 此会话0隔离将阻止非特权用户对您的服务执行破碎攻击 ,因为他们在不同的会话中获取其交互式桌面。 Shatter attacks are the main reason why this 'interaction with desktop' was considered bad practice and if you are using Vista or later, it should be ok if you cannot avoid it (or will have to spend too much effort to do it). 粉碎攻击是这种“与桌面交互”被认为是不良做法的主要原因,如果您使用Vista或更高版本,如果您无法避免它(或者将不得不花费太多精力去做它)应该没问题。
So, if things are working fine as they are, you are probably ok. 所以,如果事情正常,你可能还可以。
Of course, after an OS update, things might just stop working, so it is probably better to prepare to move the dependency on interactivity out, as you don't really need it. 当然,在操作系统更新之后,事情可能会停止工作,因此最好准备将依赖性转移到外部,因为您并不真正需要它。
I know this is a bit late but in this circumstance i would use the task scheduler and not bother with the windows service. 我知道这有点晚了,但在这种情况下,我会使用任务调度程序,而不是打扰Windows服务。 The task scheduler has a comprehensive set of scheduling options and can run console applications without issue. 任务计划程序具有一组全面的计划选项,可以毫无问题地运行控制台应用程序。
If you can, I would recommend rewriting your executables that handle the move to not use an output window. 如果可以,我建议重写处理移动的可执行文件,以便不使用输出窗口。 If they are standard, console applications with no output, you can execute them from within a service without requiring "Allow service to interact with desktop". 如果它们是标准的,没有输出的控制台应用程序,您可以在服务中执行它们,而无需“允许服务与桌面交互”。 This provides you all of the benefits, without any changes to your service. 这为您提供了所有好处,而无需对您的服务进行任何更改。
Is the subprocess just a console application? 子流程只是一个控制台应用程序吗? I've not written Windows Services, but I think perhaps just starting the subprocess without a window would be sufficient. 我没有编写Windows服务,但我想也许只是在没有窗口的情况下启动子进程就足够了。 Use the overload of Process.Start that takes a ProcessStartInfo and set ProcessStartInfo.CreateNoWindow to true. 使用ProcessStart的重载,它接受ProcessStartInfo并将ProcessStartInfo.CreateNoWindow设置为true。
http://msdn.microsoft.com/en-us/library/system.diagnostics.processstartinfo.createnowindow.aspx http://msdn.microsoft.com/en-us/library/system.diagnostics.processstartinfo.createnowindow.aspx
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.