在屏幕保护程序中生成子进程 [英] Spawning child processes in a screensaver

查看:45
本文介绍了在屏幕保护程序中生成子进程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用.NET/C#编写的屏幕保护程序,它依赖于运行的后台进程.在安装过程中将后台进程添加到用户的启动程序中时,最好不要在安装屏幕保护程序后要求用户重新启动计算机.该过程本身必须在当前用户的凭据下运行,因此使用Windows服务是不可能的.

I have a Screensaver written in .NET / C# that is dependent on a background process running. While the background process is added to the user's startup programs on install, it would still be nice to not require the user to reboot their machine after installing the screensaver. The process itself has to run under the current user's credentials, so using a Windows Service for this is out of the question.

为此,我想到的最佳解决方案是仅在使用.NET的Process类时检测启动屏幕保护程序时是否正在运行后台进程,如果没有启动则启动它.但是,我注意到这样做有两个相关的问题:

The best solution I've thought of for this is to detect whether the background process is running when the screen saver starts, and start it if it's not, just using .NET's Process class. However, I'm noticing two somewhat related issues with doing this:

1)Windows似乎总是认为屏幕保护程序正在运行,而屏幕保护程序进程或由屏幕保护程序创建的任何子进程仍在运行.最终的结果是,屏幕保护程序将自行启动并生成该进程,但将永远不会再次启动,因为Windows认为第一个屏幕保护程序仍处于活动状态,因为后台进程仍在运行.

1) Windows seems to always think that the screensaver is running while the screensaver process, or any child process created by the screensaver, is still running. The net result of this is that the screensaver will start on its own and spawn the process, but will never start again, because Windows thinks the first screensaver is still active because the background process is still running.

2)如果将计算机设置为在弹出屏幕保护程序时锁定计算机,则退出屏幕保护程序后,用户将被留下空白屏幕,并且必须显式ctrl + alt + delete登录.后台进程在WinLogon的桌面下运行,Windows再次等待退出屏幕保护程序.

2) If the computer is set up to lock the computer when the screensaver pops up, the user will be left with a blank screen after exiting the screensaver and has to explicitly ctrl+alt+delete to log in. This happens because the background process is running under WinLogon's desktop and once again, Windows is waiting for the screensaver to exit.

有什么办法解决吗?我能想到的最好的办法是找到某种方法来强制后台进程以explorer.exe的子进程而不是屏幕保护程序本身运行,但是我不确定执行此操作的最佳方法是什么,或者如果可能的话.我试过p/调用Win32 API的CreateProcess方法以及各种参数,但也没有成功.

Is there any way around this? The best thing I can think of is find some way to force the background process to run as a child of explorer.exe instead of the screensaver itself, but I'm not sure what the best way to go about doing that would be, or if it's even possible. I've tried p/invoking the Win32 API's CreateProcess method as well with various parameters to no success as well.

推荐答案

作为一个简单的解决方法,您可以将后台进程的运行与屏幕保护程序的运行相关联-如果屏幕保护程序需要启动支持进程,请使其还负责关闭该过程.这样,在第一次重新启动之前,您将可以使用某些功能,尽管功能有所减少.

As a simple workaround, you could tie the running of the background process to the running of the screensaver - if the screensaver needs to start the supporting process, make it responsible for shutting down that process as well. You'd then have something that works, albeit with reduced functionality, prior to the first reboot.

或者,作为一种更复杂的解决方案,考虑到一个进程可以使用不同的凭据启动另一个进程,则您应该能够创建一个Windows服务,该服务负责使用适当的凭据启动后台进程,这是一种看门狗服务,可确保实际的后台进程正在运行.

Alternatively, as a more complex solution, given it's possible for one process to start another with different credentials you should be able create a windows service that's responsible for launching the background process with appropriate credentials, kind of a watchdog service that makes sure the actual background process is running.

这篇关于在屏幕保护程序中生成子进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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