在屏幕保护程序中生成子进程

发布于 2024-10-16 01:37:48 字数 679 浏览 4 评论 0原文

我有一个用 .NET / C# 编写的屏幕保护程序,它依赖于正在运行的后台进程。虽然后台进程在安装时添加到用户的启动程序中,但如果用户在安装屏幕保护程序后不需要重新启动计算机,那就太好了。该进程本身必须在当前用户的凭据下运行,因此使用 Windows 服务来执行此操作是不可能的。

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

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

2) 如果计算机设置为在屏幕保护程序弹出时锁定计算机,则用户在退出屏幕保护程序后将留下空白屏幕,并且必须显式 ctrl+alt+delete 才能登录。发生这种情况是因为后台进程正在 WinLogon 桌面下运行,Windows 再次等待屏幕保护程序退出。

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

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.

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 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) 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.

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.

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

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

发布评论

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

评论(1

魂归处 2024-10-23 01:37:48

作为一个简单的解决方法,您可以将后台进程的运行与屏幕保护程序的运行联系起来 - 如果屏幕保护程序需要启动支持进程,则让它也负责关闭该进程。然后,在第一次重新启动之前,您就可以得到一些可以运行的东西,尽管功能有所减少。

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

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.

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.

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