Jump to content

Recommended Posts

Posted

Hello, I have run into a problem with a vb.net program I am developing, and was wondering if anyone could help.

 

Background:

The program runs as a service, which may be the root cause of my issue.

 

I have found a couple of ways of getting the screen resolution, which all report the same thing.

 

WMI version

    Private Sub getRes()
       
       Dim objWMIService, objComputer As Object

               objWMIService = GetObject("Winmgmts:{impersonationLevel=impersonate,(Debug,Shutdown)}")
       For Each objComputer In objWMIService.InstancesOf("Win32_DisplayConfiguration")
           Utils.WriteToEventLog("WMIRes: " & objComputer.PelsWidth & "x" & objComputer.PelsHeight,EventLogEntryType.Information)

       Next
   End Sub

 

Easy vb.net version

private sub getRes()
   dim Height as Integer = my.computer.screen.bounds.height
   dim Width as Integer = my.computer.screen.bounds.width
   Utils.WriteToEventLog("Res: " & Width & "x" & Height, EventLogEntryType.Information)
end Sub

 

More comlplex vb.net version

 

private sub getRes()
  for each device in my.computer.screen.allscreens
       height = device.bounds.height
       width = device.bounds.width
.....

 

 

All very straight-forward. Except that it reports back 1024x768 when the real resolution is 1280x800

 

If I run the code in a new project with a windows form, it reports correctly.

So, how can my service get the resolution of the screen of the device that it is running on?

Posted
The program runs as a service, which may be the root cause of my issue

 

Google "session 0 isolation" to find out why.

 

There might be some trick or arcane dotNet call to get you around this, but I suspect you have to p/invoke the WTS API (for an example of the territory we're in run QWINSTA) to get the physical console user's session ID, and via that info about their session e.g. desktop dimensions. And if you're doing this because you want your service to do something on the user's desktop then the google I suggested should turn up typical methods.

  • Thanks 1
Posted

Yep, that looks like the reason.

Cheers.

 

I dont need to display anything on the screen, but just get the physical resolution in order to correctly select a file to copy. This must be done before user login is displayed :-(

(Basically the desktop background is chosen from a set of backgrounds based on screen resolution. Windows 7 only supports certain resolutions and some of our machines dont fit those limited choices and so use the default image. This I wanted to change based on the actual res.)

 

ie.

defaultBackground.jpg

background1024x1280.jpg

background1280x800.jpg

 

Windows 7 will detect and display 1024x768 no trouble, and other common ones, (1024x768 etc)

However anything not on the list will get defaultbackground.

1280x800 isnt on the list, so I need to copy this file to defaultBackground as a service before it is used. However, becuase of this session 0 thing, it always thinks the screen is 1024x768

 

Annoying.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...