Jump to content

WMI Help - Win32_DesktopMonitor for Terminal Session


Recommended Posts

Posted

Hi,

 

I was wondering if there is a equivalent WMI to Win32_DesktopMonitor for an RDP session to determine the resolution of the session please?

 

I have a little logon script that will look at the screen resolution of a computer and apply the correct wallpaper. When using it on RDP it uses the host resolution. It uses Win32_DesktopMonitor so if there is something that will work for the session that would help.

 

@Arthur is good with WMI so he maybe able to help ;)

 

Thanks

Posted

If you run the following VBScript in your RDP session, does it return the correct resolution?

 

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_DisplayConfiguration",,48)
For Each objItem in colItems
   Wscript.Echo objItem.PelsWidth & " x " & objItem.PelsHeight
Next

Posted

What about this VBScript? :)

 

ScreenRes = funcScreenResolution() 

Function funcScreenResolution() 
   Set objIE = CreateObject("InternetExplorer.Application") 
   objIE.Navigate("about:blank") 
   Do Until objIE.readyState = 4: Loop 
       width = objIE.document.ParentWindow.screen.width 
       height = objIE.document.ParentWindow.screen.height 
   objIE.Quit 
   funcScreenResolution = array(width,height) 
End Function 

wscript.Echo ScreenRes(0) & " x " & ScreenRes(1)

 

How are you connecting to the session e.g. via an RDP file?

  • Thanks 1
Posted

How are you connecting to the session e.g. via an RDP file?

 

Via HP ThinClients. But i run the first script via a RDP session using sonicwall SSL VPN.

 

The second script works :)

 

This is a sample of the script we use. How would i go about adapting it please?

 

Thanks

 

Set objWMIService = GetObject("Winmgmts:\\.\root\cimv2") 
Set objSh = CreateObject("Wscript.Shell")
Set colItems = objWMIService.ExecQuery("Select * From Win32_DesktopMonitor where DeviceID = 'DesktopMonitor1'",,0) 
For Each objItem in colItems 
   intHorizontal = objItem.ScreenWidth 
   intVertical = objItem.ScreenHeight 
Next

strResolution = CStr(intHorizontal) & " x " & CStr(intVertical)

Select Case strResolution
Case "1024 x 768"
       strWallpaperPath = "C:\Program Files\Wallpaper\Staff\1024x768.jpg"
Case "1280 x 800"
       strWallpaperPath = "C:\Program Files\Wallpaper\Staff\1280x800.jpg"
Case "1280 x 1024"
       strWallpaperPath = "C:\Program Files\Wallpaper\Staff\1280x1024.jpg"
Case Else
End Select

'Set the reg value
objSh.RegWrite "HKCU\Control Panel\Desktop\Wallpaper", strWallpaperPath, "REG_SZ"

'Apply the change
objSh.Run "%windir%\System32\RUNDLL32.EXE user32.dll,UpdatePerUserSystemParameters", 0, False

Posted

Its because i am using a Windows VM on my Mac to connect. Its just the window size i dragged the VM to and then connected full screen. In production its just the usual resolutions :)

 

To be honest i would rather go for a wallpaper that matches the resolution if we can.

 

Thanks

Posted

Would the script be something like the below?

 

Thanks

 

ScreenRes = funcScreenResolution() 

Function funcScreenResolution() 
   Set objIE = CreateObject("InternetExplorer.Application") 
   objIE.Navigate("about:blank") 
   Do Until objIE.readyState = 4: Loop 
       width = objIE.document.ParentWindow.screen.width 
       height = objIE.document.ParentWindow.screen.height 
   objIE.Quit 
   funcScreenResolution = array(width,height) 
End Function 

strResolution = ScreenRes(0) & " x " & ScreenRes(1)

Select Case strResolution
Case "1024 x 768"
       strWallpaperPath = "C:\Program Files\Wallpaper\Staff\1024x768.jpg"
Case "1280 x 800"
       strWallpaperPath = "C:\Program Files\Wallpaper\Staff\1280x800.jpg"
Case "1280 x 1024"
       strWallpaperPath = "C:\Program Files\Wallpaper\Staff\1280x1024.jpg"
Case Else
End Select

'Set the reg value
objSh.RegWrite "HKCU\Control Panel\Desktop\Wallpaper", strWallpaperPath, "REG_SZ"

'Apply the change
objSh.Run "%windir%\System32\RUNDLL32.EXE user32.dll,UpdatePerUserSystemParameters", 0, False

Posted (edited)

I made a few changes to your script and tested it in a Windows 7 VM, but can't get the wallpaper to change. Something to do with RunDLL32 perhaps? :confused:

 

I'll have another look tomorrow later today when my brain is working properly. :)

Edited by Arthur
  • Thanks 1
Posted

This seems to work. I shall feedback and let you know how i get on.

 

Thanks

 

Set objSh = CreateObject("Wscript.Shell")

ScreenRes = funcScreenResolution() 
Function funcScreenResolution() 
   Set objIE = CreateObject("InternetExplorer.Application") 
   objIE.Navigate("about:blank") 
   Do Until objIE.readyState = 4: Loop 
       width = objIE.document.ParentWindow.screen.width 
       height = objIE.document.ParentWindow.screen.height 
   objIE.Quit 
   funcScreenResolution = array(width,height) 
End Function 

strResolution = ScreenRes(0) & " x " & ScreenRes(1)

Select Case strResolution
Case "1024 x 768"
       strWallpaperPath = "C:\Program Files\Wallpaper\Staff\1024x768.jpg"
Case "1280 x 800"
       strWallpaperPath = "C:\Program Files\Wallpaper\Staff\1280x800.jpg"
Case "1280 x 1024"
       strWallpaperPath = "C:\Program Files\Wallpaper\Staff\1280x1024.jpg"
Case Else
End Select

'Set the reg value
objSh.RegWrite "HKCU\Control Panel\Desktop\Wallpaper", strWallpaperPath, "REG_SZ"

'Apply the change
objSh.Run "%windir%\System32\RUNDLL32.EXE user32.dll,UpdatePerUserSystemParameters", 0, False

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...