question

LoPALAZZI-4508 avatar image
0 Votes"
LoPALAZZI-4508 asked RLWA32-6355 commented

Windows service not detecting multiple monitors (C#)



Hello,


I am developping a Windows service in C# but it seems that it's not able to see all the monitors I connected to the computer.


I tried :

  • to look inside the Win32_VideoController class but I only see one screen when there is two (+ the Windisc)

  • run this command from powershell : Get-WmiObject -Class Win32_VideoController but there is not all informations needed

  • loop in Screen.AllScreens but I only see Windisc


Can someone help me ?


Thank you !

dotnet-csharp
· 4
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@LoPALAZZI-4508

run this command from powershell : Get-WmiObject -Class Win32_VideoController but there is not all informations needed

Do you mean that the information you need can be obtained in this way, but there will be more unneeded information?
Powershell should be able to filter to show what you need.
Do we have to use Windows Service? Maybe you can describe your needs, we can use other methods instead?

0 Votes 0 ·

I want to have all resolution of all the screens.

I can't change the way my code is, I need it to be on a Windows service.

0 Votes 0 ·

@LoPALAZZI-4508
Can you use Powershell to get enough information?
If Powershell can meet your needs, you can ask Powershell experts for help, ask them to write appropriate commands to filter the information you need, and then we should be able to call this command in c#.
Or do I misunderstand what you mean?

0 Votes 0 ·

If you don't need the isolation for services provided by session 0 and your service can run correctly in the context of a logged-on user take a look at Per user services in Windows 10 and Windows Server. Such services run in the logged-on user's interactive session.


0 Votes 0 ·
cheong00 avatar image
0 Votes"
cheong00 answered LoPALAZZI-4508 commented

You may try Win32_Desktopmonitor instead, however I think active monitors are binding to user sessions (so remote desktop can support multiple-monitor view) so it may not work in service.

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

it's only seeing one screen out of 2

0 Votes 0 ·
lextm avatar image
1 Vote"
lextm answered LoPALAZZI-4508 commented

Due to session isolation, your Windows service app in session 0 can only see an emulated screen (for compatibility purposes), and a log on user can see all physical screens in his/her user session,

https://techcommunity.microsoft.com/t5/ask-the-performance-team/application-compatibility-session-0-isolation/ba-p/372361

Therefore, if you want to run some code regarding physical screens, you shouldn't put such in a Windows service app, but a desktop app running in user sessions.

· 4
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

But with some code I am able to get information about one screen so how is it possible ?

0 Votes 0 ·

What you got is exactly the emulated screen I mentioned (1024*768 resolution, non interactive). Everything (hardware like screens) can be emulated at driver level.

0 Votes 0 ·

No because I have 1080x1920 px...

0 Votes 0 ·

No because I got size of 1920x1080 which is one of the screens...

0 Votes 0 ·