简体   繁体   English

作为Windows服务运行时,如何获取活动监视器的数量? C ++

[英]When running as a windows service, how do i get the number of active monitors? C++

I have ran into an issue when retrieving the number of active monitors while the exe is running as a windows service. 当exe作为Windows服务运行时,在检索活动监视器的数量时遇到了一个问题。 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. 我尝试使用EnumDisplayDevices和GetSystemMetrics(SM_CMONITROS)获取监视器的数量,当以控制台模式运行它们(由用户启动)时,这两种方法将为我提供正确的监视器数量,但是当我将exe注册为服务并通过Windows服务运行它,报告的监视器数量被证明是不正确的。

Is there any other way to determine the number of active monitors while running as a windows service? 还有其他方法来确定作为Windows服务运行时活动监视器的数量吗? 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. 但是,为了进行交互,服务必须获得对“真实”桌面的访问权限,因此监视器数量应该正确。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM