EnumDisplayDevices behaving differently in a Windows Service

Hi All,

I had an application, the code of which i used to create a windows service. The windows service is up now (many thanks to guys here at osronline) but I am observing an odd behavior with the service.
I’d like to mention here that this all I am trying over VirtualBox with Win 7, 32-bit.

While as a console app, the EnumDisplayDevices is reporting a total of 4 display devices (\.\DISPLAY1 , \.\DISPLAYV1, \.\DISPLAYV2 and \.\DISPLAYV3), it is reporting only three devices (\.\DISPLAYV1, \.\DISPLAYV2 and \.\DISPLAYV3)) while running as a service. It’s not reporting the Primary Display. I am not sure of the reasons for this behavior as the code is all same for both and works in console but not in service.
I would greatly appreciate if anyone could provide me some inputs.

Thanks!

xxxxx@gmail.com wrote:

I had an application, the code of which i used to create a windows service. The windows service is up now (many thanks to guys here at osronline) but I am observing an odd behavior with the service.
I’d like to mention here that this all I am trying over VirtualBox with Win 7, 32-bit.

While as a console app, the EnumDisplayDevices is reporting a total of 4 display devices (\.\DISPLAY1 , \.\DISPLAYV1, \.\DISPLAYV2 and \.\DISPLAYV3), it is reporting only three devices (\.\DISPLAYV1, \.\DISPLAYV2 and \.\DISPLAYV3)) while running as a service. It’s not reporting the Primary Display. I am not sure of the reasons for this behavior as the code is all same for both and works in console but not in service.

We have tried to tell you several times that a service cannot access the
primary desktop. I suspect that’s what you’re seeing here. The main
display device is not created within the service “session”.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

The odd thing about this result is not that you don’t see \.\DISPLAY1, but
that you see any display devices returned from this call.

services generally cannot access any GDI surfaces that correspond to
anything a user might see on a monitor or RDP session

“Tim Roberts” wrote in message news:xxxxx@ntdev…

xxxxx@gmail.com wrote:

I had an application, the code of which i used to create a windows
service. The windows service is up now (many thanks to guys here at
osronline) but I am observing an odd behavior with the service.
I’d like to mention here that this all I am trying over VirtualBox with
Win 7, 32-bit.

While as a console app, the EnumDisplayDevices is reporting a total of 4
display devices (\.\DISPLAY1 , \.\DISPLAYV1, \.\DISPLAYV2 and
\.\DISPLAYV3), it is reporting only three devices (\.\DISPLAYV1,
\.\DISPLAYV2 and \.\DISPLAYV3)) while running as a service. It’s not
reporting the Primary Display. I am not sure of the reasons for this
behavior as the code is all same for both and works in console but not in
service.

We have tried to tell you several times that a service cannot access the
primary desktop. I suspect that’s what you’re seeing here. The main
display device is not created within the service “session”.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

You have to have your service connect a process to the “on glass session”
in order to manage the display. This is more or less clearly documented.

Mark Roddy

On Mon, Oct 28, 2013 at 9:06 AM, wrote:

> Hi All,
>
> I had an application, the code of which i used to create a windows
> service. The windows service is up now (many thanks to guys here at
> osronline) but I am observing an odd behavior with the service.
> I’d like to mention here that this all I am trying over VirtualBox with
> Win 7, 32-bit.
>
> While as a console app, the EnumDisplayDevices is reporting a total of 4
> display devices (\.\DISPLAY1 , \.\DISPLAYV1, \.\DISPLAYV2 and
> \.\DISPLAYV3), it is reporting only three devices (\.\DISPLAYV1,
> \.\DISPLAYV2 and \.\DISPLAYV3)) while running as a service. It’s not
> reporting the Primary Display. I am not sure of the reasons for this
> behavior as the code is all same for both and works in console but not in
> service.
> I would greatly appreciate if anyone could provide me some inputs.
>
> Thanks!
>
> —
> NTDEV is sponsored by OSR
>
> Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev
>
> OSR is HIRING!! See http://www.osr.com/careers
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>

We have never been told the purpose of this access, that is, the
inevitable “What problem are you trying to solve?”

Apparently, the notion that you can’t access a display surface from a
service does not seem to impact the OP.

The explanation for the strange behavior is simple: you are trying to do
something that is unsupported. Stop trying to do it.
joe

xxxxx@gmail.com wrote:
> I had an application, the code of which i used to create a windows
> service. The windows service is up now (many thanks to guys here at
> osronline) but I am observing an odd behavior with the service.
> I’d like to mention here that this all I am trying over VirtualBox with
> Win 7, 32-bit.
>
> While as a console app, the EnumDisplayDevices is reporting a total of 4
> display devices (\.\DISPLAY1 , \.\DISPLAYV1, \.\DISPLAYV2 and
> \.\DISPLAYV3), it is reporting only three devices (\.\DISPLAYV1,
> \.\DISPLAYV2 and \.\DISPLAYV3)) while running as a service. It’s not
> reporting the Primary Display. I am not sure of the reasons for this
> behavior as the code is all same for both and works in console but not
> in service.

We have tried to tell you several times that a service cannot access the
primary desktop. I suspect that’s what you’re seeing here. The main
display device is not created within the service “session”.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.


NTDEV is sponsored by OSR

Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev

OSR is HIRING!! See http://www.osr.com/careers

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

On Oct 28, 2013, at 7:35 PM, xxxxx@flounder.com wrote:

We have never been told the purpose of this access, that is, the
inevitable "What problem are you trying to solve??

He did say that he needs to make an escape call into the Direct3D provider, although no hints about what the escape code might be doing.

Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

> On Oct 28, 2013, at 7:35 PM, xxxxx@flounder.com wrote:

> We have never been told the purpose of this access, that is, the
> inevitable "What problem are you trying to solve?”

He did say that he needs to make an escape call into the Direct3D
provider, although no hints about what the escape code might be doing.

Yes, I know, but that isn’t an answer; the question remains.

For example, if it is trying to obtain some kind of statistics about
display information, that’s different than if he’s trying to get some kind
of effect on a display device.
joe


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.


NTDEV is sponsored by OSR

Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev

OSR is HIRING!! See http://www.osr.com/careers

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

From Vista+, this is deprecated and IIRC not working anymore, probably an AppCompat flag is needed for this.
“Mark Roddy” wrote in message news:xxxxx@ntdev…
You have to have your service connect a process to the “on glass session” in order to manage the display. This is more or less clearly documented.

Mark Roddy

On Mon, Oct 28, 2013 at 9:06 AM, wrote:

Hi All,

I had an application, the code of which i used to create a windows service. The windows service is up now (many thanks to guys here at osronline) but I am observing an odd behavior with the service.
I’d like to mention here that this all I am trying over VirtualBox with Win 7, 32-bit.

While as a console app, the EnumDisplayDevices is reporting a total of 4 display devices (\.\DISPLAY1 , \.\DISPLAYV1, \.\DISPLAYV2 and \.\DISPLAYV3), it is reporting only three devices (\.\DISPLAYV1, \.\DISPLAYV2 and \.\DISPLAYV3)) while running as a service. It’s not reporting the Primary Display. I am not sure of the reasons for this behavior as the code is all same for both and works in console but not in service.
I would greatly appreciate if anyone could provide me some inputs.

Thanks!


NTDEV is sponsored by OSR

Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev

OSR is HIRING!! See http://www.osr.com/careers

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

Thank you all for your responses.

Marion, you are right. But sometimes EnumDisplayDevices works and shows the display devices and sometimes not.

Mark, can you show some more light on "service connect a process to the “on glass session” " particularly on “glass session”? I couldn’t get any info on this.

Joe, the ultimate goal is to exchange some data from a custom display driver using D3DKMTEscape call. The data is related to the framebuffer.

The outstanding question was “Why it works with console but not with service?”

And I believe the answer has something to do with: “because session 0 isn’t connected to the console (from a thread on msdn) and this is what services use” AND Tim, as you say, a service cannot access the primary desktop.

WTSGetActiveConsoleSessionId().
WTSQueryUserToken().
… do some stuff to duplicate the token …
CreateProcessAsUser()

Also you have to handle the case where nobody is logged in.

Mark Roddy

On Tue, Oct 29, 2013 at 10:50 AM, wrote:

> Thank you all for your responses.
>
> Marion, you are right. But sometimes EnumDisplayDevices works and shows
> the display devices and sometimes not.
>
> Mark, can you show some more light on "service connect a process to the
> “on glass session” " particularly on “glass session”? I couldn’t get any
> info on this.
>
> Joe, the ultimate goal is to exchange some data from a custom display
> driver using D3DKMTEscape call. The data is related to the framebuffer.
>
> The outstanding question was “Why it works with console but not with
> service?”
>
> And I believe the answer has something to do with: “because session 0
> isn’t connected to the console (from a thread on msdn) and this is what
> services use” AND Tim, as you say, a service cannot access the primary
> desktop.
>
>
> —
> NTDEV is sponsored by OSR
>
> Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev
>
> OSR is HIRING!! See http://www.osr.com/careers
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>

I would have thought that by now the answer to your ‘outstanding’ question
would be obvious to you: services run under a different window station and
desktop (GDI constructs) that has no relation to the physical graphics card
or monitors. It is therefore impossible to access GDI constructs (or
directx etc.) that correspond to the physical graphics card etc. from
services without using the Windows station APIs (be aware that by default
access is denied)

If you can achieve your task by accessing your driver using an out of band
interface (not one controlled by GDI etc) then you can make your program
work as a service, but if you need access to the primary display (GDI
construct) then you must either run in an interactive session or be aware
and entitled to interact with windows stations.

read more on terminal services / fast user switching and general GDI
concepts. IIRC the introduction of multiple windows stations was the last
major change to the rules (circa 2002) since GDI when to KM in NT 4. I am
sure that the implementation has changed since then, but the UI still has
the same annoying cursor locking issue over non-responsive applications that
frustrated me in NT 3.51

wrote in message news:xxxxx@ntdev…

Thank you all for your responses.

Marion, you are right. But sometimes EnumDisplayDevices works and shows the
display devices and sometimes not.

Mark, can you show some more light on "service connect a process to the “on
glass session” " particularly on “glass session”? I couldn’t get any info on
this.

Joe, the ultimate goal is to exchange some data from a custom display driver
using D3DKMTEscape call. The data is related to the framebuffer.

The outstanding question was “Why it works with console but not with
service?”

And I believe the answer has something to do with: “because session 0 isn’t
connected to the console (from a thread on msdn) and this is what services
use” AND Tim, as you say, a service cannot access the primary desktop.

> concepts. IIRC the introduction of multiple windows stations was the last

major change to the rules (circa 2002)

No, it was in late 1990ies with NT4 SPs which introduced Terminal Server.

Surely it was in w2k.

the same annoying cursor locking issue over non-responsive applications that
frustrated me in NT 3.51

…and even the more annoying issue in bringing forward the app which wishes so, interrupting your typing (sometimes password typing).


Maxim S. Shatskih
Microsoft MVP on File System And Storage
xxxxx@storagecraft.com
http://www.storagecraft.com

Maxim S. Shatskih wrote:

> concepts. IIRC the introduction of multiple windows stations was the last
> major change to the rules (circa 2002)
No, it was in late 1990ies with NT4 SPs which introduced Terminal Server.

Surely it was in w2k.

But that Terminal Server code came from Citrix, which had the concept
clear back to NT 3.51.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

And terminal services (aka fast user switching) was finally implemented
properly by adding support for multiple ‘sessions’ via windows stations and
desktops for w2k - though the code was way too buggy until server 2003

“Tim Roberts” wrote in message news:xxxxx@ntdev…

Maxim S. Shatskih wrote:

> concepts. IIRC the introduction of multiple windows stations was the
> last
> major change to the rules (circa 2002)
No, it was in late 1990ies with NT4 SPs which introduced Terminal Server.

Surely it was in w2k.

But that Terminal Server code came from Citrix, which had the concept
clear back to NT 3.51.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

Thank you all.

MM, I get you. Yes,the answer was obvious.

Now, one more clarification:
I have seen a service example sending IOCTLs to the driver. We can try to get the needed info from the driver using IOCTLs instead of using D3DKMTEscape.

Can we use CreateFile() to get a handle to the device?? Something like: CreateFile ( "\\.\DISPLAY2…)
I tried it and @Marion, you were right! I am getting ERROR_ACCESS_DENIED as Error Code when CreateFile fails.

If IOCTLs are not possible, then Mark’s suggestion of “On Glass session” should work right?