Page 1 of 1 1
Topic Options
#189003 - 2008-08-04 12:58 AM Query Screen Resolution
xempa Offline
Fresh Scripter

Registered: 2006-08-12
Posts: 37
Hi I've been trawling the internet trying to find an easy way through kix to query a remote users screen resolution

The purpose , so the appropriate sized screen saver msi can be installed to the remote users machine

I was thinking an if statement e.g. if 800 X 600 then run a 800 X 600 msi

I have found this script but not sure how to use it ?

Any help would be appreciated

? "Video"
?

; Query video adapter properties
$colItems = $objWMIService.ExecQuery( "Select * from Win32_VideoController", , 48 )
; Display error number if applicable
If @ERROR
GoTo ShowError
EndIf
; Display results
For Each $objItem in $colItems
? " Name: " + $objItem.Name
? " Video Processor: " + $objItem.VideoProcessor
? " Adapter RAM: " + ( ( $objItem.AdapterRAM + 524288 ) / 1048576 ) + " MB"
? " Video Mode Description: " + $objItem.VideoModeDescription
?
Next

; Done
Quit 0

Top
#189004 - 2008-08-04 03:53 AM Re: Query Screen Resolution [Re: xempa]
xempa Offline
Fresh Scripter

Registered: 2006-08-12
Posts: 37
Responding to my own question something like this which works well as a VBS script. How do I convert to kix ?

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

if intHorizontal = 1024 then
msgbox "install screensaver 1024 here..."
End if
if intHorizontal = 800 then
msgbox " install screensaver 800 here..."
End if

Top
#189005 - 2008-08-04 04:16 AM Re: Query Screen Resolution [Re: xempa]
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4567
Loc: USA
There is a function in the UDFs called GetScreenRes, but it doesn't support remote computers. Loosely based on GetScreenRes and using Kixomatic, this should get you going.

? screenres()
;? screenres("RemoteComputerName") 
 
Function ScreenRes(optional $remotecomputer) if $remotecomputer="" $strComputer = "." endif $objWMIService = GetObject("winmgmts:\\" + $strComputer + "\root\cimv2") if $objwmiservice $colItems = $objWMIService.ExecQuery("Select * from Win32_VideoController",,48) For each $objItem in $colItems if $ScreenRes="" $screenres=trim(split($objItem.VideoModeDescription,"x")[0]) + "x" + trim(split($objItem.VideoModeDescription,"x")[1]) endif Next if $screenres exit 0 else exit -1 else exit @error endif endfunction


Do a search for kixomatic if you would like to see how easy it is to build scripts with wmi. Your second post/vbscript is more direct... I'll see what I can do.


Edited by Allen (2008-08-04 04:30 AM)

Top
#189006 - 2008-08-04 04:29 AM Re: Query Screen Resolution [Re: Allen]
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4567
Loc: USA
I updated the code above, there was an error. Here is another example based on your vbscript.

? screenreswidth()
? screenresheight()
;? screenreswidth("RemoteComputerName") 
 

Function ScreenResWidth(optional $remotecomputer) dim $objwmiservice, $colitems, $objitem if $remotecomputer="" $strComputer = "." endif $objWMIService = GetObject("winmgmts:\\" + $strComputer + "\root\cimv2") if $objwmiservice $colItems = $objWMIService.ExecQuery("Select * From Win32_DesktopMonitor where DeviceID = 'DesktopMonitor1'",,0) For Each $objItem in $colItems $ScreenResWidth = $objItem.ScreenWidth Next endif endfunction
Function ScreenResHeight(optional $remotecomputer) dim $objwmiservice, $colitems, $objitem if $remotecomputer="" $strComputer = "." endif $objWMIService = GetObject("winmgmts:\\" + $strComputer + "\root\cimv2") if $objwmiservice $colItems = $objWMIService.ExecQuery("Select * From Win32_DesktopMonitor where DeviceID = 'DesktopMonitor1'",,0) For Each $objItem in $colItems $ScreenResHeight = $objItem.ScreenHeight Next endif endfunction

Top
#189007 - 2008-08-04 04:35 AM Re: Query Screen Resolution [Re: Allen]
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4567
Loc: USA
So something like

 Code:
select
  case screenreswidth() = 1024
    ;do stuff 1024
  case screereswidth() = 800
    ;do stuff 800
  case 1
    ; Must be using some other resolution
endselect


Just add more cases to hit all the resolutions.

Top
#189009 - 2008-08-04 09:42 AM Re: Query Screen Resolution [Re: Allen]
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Which user's context are you reading when you pull the screen size remotely via WMI? Is it always the same for all users on a particular device?

How are you going to deal with multiple screens (e.g. laptops) where the external and internal monitors will be different resolutions?

Top
#189010 - 2008-08-04 09:57 AM Re: Query Screen Resolution [Re: Richard H.]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
This

 Code:
$wmiColl = GetObject("WinMgmts:root/cimv2").ExecQuery("Select * FROM Win32_DesktopMonitor")
For Each $wmiObj In $wmiColl
	Select
		Case $wmiObj.DeviceID = "DesktopMonitor1"
			$screenres1 = CSTR($wmiObj.ScreenWidth) + "x" + CSTR($wmiObj.ScreenHeight)
		Case $wmiObj.DeviceID = "DesktopMonitor2"
			$screenres2 = CSTR($wmiObj.ScreenWidth) + "x" + CSTR($wmiObj.ScreenHeight)
	EndSelect
Next


works for me. It gets the resolution from the first monitor/connector and set the wallpaper depending on the outcome. If you need the second monitor (or both) you could use DesktopMonitor1 and/or DesktopMonitor2.


Edited by Mart (2008-08-04 09:57 AM)
Edit Reason: typo
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#189012 - 2008-08-04 01:50 PM Re: Query Screen Resolution [Re: Mart]
xempa Offline
Fresh Scripter

Registered: 2006-08-12
Posts: 37
Wow....! many thanks to all of you who have contributed to helping. In the end I have used a combination of your scripts to form the following. I hope you don't mind

Allen, Richard and Mart many thanks for your help

$wmiColl = GetObject("WinMgmts:root/cimv2").ExecQuery("Select * FROM Win32_DesktopMonitor")
For Each $wmiObj In $wmiColl
Select
Case $wmiObj.DeviceID = "DesktopMonitor1"
$screenres1 = CSTR($wmiObj.ScreenWidth) + "x" + CSTR($wmiObj.ScreenHeight)
Case $wmiObj.DeviceID = "DesktopMonitor2"
$screenres2 = CSTR($wmiObj.ScreenWidth) + "x" + CSTR($wmiObj.ScreenHeight)
EndSelect
Next

select
case $screenres1 = "1024x768"
;do stuff 1024
? "do stuff 1024 X 768 "
case $screenres1 = "800x600"
;do stuff 800
? "do stuff 800 X 600"
case 1
; Must be using some other resolution
endselect


select
case $screenres2 = "1024x768"
;do stuff 1024
? "do stuff 1024 X 768"
case $screenres2 = "800x600"
;do stuff 800
? "do stuff 800 X 600"
case 1
; Must be using some other resolution
endselect

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 1376 anonymous users online.
Newest Members
batdk82, StuTheCoder, M_Moore, BeeEm, min_seow
17885 Registered Users

Generated in 0.065 seconds in which 0.031 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org