简体   繁体   English

“允许服务与桌面交互”的替代方案?

[英]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服务分开,因为

  • it makes it easier to debug and doesn't require a full windows service redeploy. 它使调试更容易,并且不需要重新部署完整的Windows服务。
  • sometimes I use the same windows service to launch several executable files at different intervals (but all related to the same project). 有时我使用相同的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.

相关问题 允许 Windows 服务与桌面交互 - Allow Windows service to interact with desktop Web Api 2服务(允许服务与桌面交互) - Web Api 2 Service (allow service to interact with desktop) 在Windows服务中选中“允许服务与桌面交互”(在服务属性中) - Find “Allow service to interact with desktop” checked (in the service properties) of Windows Service 如何在windows服务安装时默认勾选“允许服务与桌面交互” - How to keep "Allow Service to interact with desktop" checked by default at the time of windows service installation 如何在Windows服务安装程序中设置“与桌面交互” - How to set “interact with desktop” in windows service installer 管理服务:将用户登录到桌面,生成可与桌面交互的进程 - Admin service: log user into desktop, spawn a process that can interact with the desktop WCF 服务中的字典替代品 - Alternative to dictionary in WCF Service 使用C#winforms与Windows中的其他桌面应用程序进行交互 - Interact with other desktop-applications in windows using C# winforms 指定wmi创建的远程进程应与桌面交互 - Specify that a remote process created by wmi should interact with the desktop 自动化引擎无法回放测试,因为它无法与桌面交互……但是桌面未锁定 - Automation engine is unable to playback the test because it is not able to interact with the desktop… but desktop not locked
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM