+ Post New Thread
Results 1 to 4 of 4
Coding Thread, vb.net help needed getting screen resolution in Coding and Web Development; Hello, I have run into a problem with a vb.net program I am developing, and was wondering if anyone could ...
  1. #1

    Join Date
    Jan 2009
    Location
    Burton On Trent
    Posts
    134
    Thank Post
    24
    Thanked 30 Times in 22 Posts
    Rep Power
    17

    vb.net help needed getting screen resolution

    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
    Code:
        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
    Code:
    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

    Code:
    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?

  2. #2

    Join Date
    Jan 2006
    Location
    Surburbia
    Posts
    2,178
    Thank Post
    74
    Thanked 307 Times in 243 Posts
    Rep Power
    115
    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.

  3. Thanks to PiqueABoo from:

    peterp (24th October 2011)

  4. #3

    Join Date
    Jan 2009
    Location
    Burton On Trent
    Posts
    134
    Thank Post
    24
    Thanked 30 Times in 22 Posts
    Rep Power
    17
    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.

  5. #4

    SYNACK's Avatar
    Join Date
    Oct 2007
    Posts
    11,172
    Thank Post
    868
    Thanked 2,699 Times in 2,288 Posts
    Blog Entries
    11
    Rep Power
    772
    You could dig through the system registry to look for the current default screen. how to read current screen resolution from registry? [Archive] - CodeGuru Forums could be a bit of work to figure out the active one though.

SHARE:
+ Post New Thread

Similar Threads

  1. Replies: 5
    Last Post: 1st July 2014, 08:34 AM
  2. Replies: 5
    Last Post: 25th June 2011, 03:09 PM
  3. VB.net get free space
    By Quackers in forum Coding
    Replies: 2
    Last Post: 16th July 2008, 01:56 PM
  4. Need help with Plasma screen install and audio on PE Suite
    By tosca925 in forum How do you do....it?
    Replies: 5
    Last Post: 26th June 2008, 11:41 PM
  5. VB.Net Help
    By mloveless in forum Coding
    Replies: 2
    Last Post: 29th June 2007, 04:24 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •