作为 Windows 服务运行时,如何获取活动监视器的数量?C++ [英] When running as a windows service, how do i get the number of active monitors? C++

查看:28
本文介绍了作为 Windows 服务运行时,如何获取活动监视器的数量?C++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 exe 作为 Windows 服务运行时检索活动监视器的数量时遇到问题.我曾尝试使用 EnumDisplayDevices 和 GetSystemMetrics(SM_CMONITROS) 来获取监视器的数量,这两种方法在以控制台模式运行它们时(意思是由用户启动)会给我正确的监视器数量,但是当我将 exe 注册为服务并通过windows服务运行它,报告的监视器数量结果不正确.

I have ran into an issue when retrieving the number of active monitors while the exe is running as a windows service. I have tried using EnumDisplayDevices and GetSystemMetrics(SM_CMONITROS) to get the number of monitors, these two methods woulds give me the correct number of monitors when running them as console mode (meaning initiated by the user), but when I register the exe as a service and run it through the windows service, the number of monitors that was reported turned out to be incorrect.

有没有其他方法可以在作为 Windows 服务运行时确定活动监视器的数量?或者任何其他工作?提前致谢!

Is there any other way to determine the number of active monitors while running as a windows service? Or any other work around? Thanks in advance!

推荐答案

出于安全原因,不允许服务与用户桌面交互.因此,它们运行在与物理桌面无关的虚拟桌面中.您可以尝试以下操作.在服务管理器的服务列表中.右键单击您的服务,转到属性并在那里登录".您可以在那里更改服务使用的帐户.使用本地系统帐户",您可以选中允许服务与桌面交互".我没有尝试过我自己.但是为了交互服务必须获得对真实"桌面的访问权限,因此监视器计数应该是正确的.

Services are not allowed to interact with the user desktop for security reason. Therefore they are running in their virtual desktop which has nothing to do with the physical one. You can try the following. In the service list of the service manager. Rightclick your service, go to properties and there to "Log On". There you can change the account the service is using. With the "Local System account" you can check the "Allow service to interact with desktop". I didn't try that my self. But for interacting the service has to get the access to the "real" desktop and therefore the monitor count should be right.

这篇关于作为 Windows 服务运行时,如何获取活动监视器的数量?C++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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