#195121 - 2009-07-30 07:20 AM
Dual monitors using UDF
|
xempa
Fresh Scripter
Registered: 2006-08-12
Posts: 37
|
Hi
I'm not sure how to query a second monitor with this UDF. Any help here would be appreciated cheers. I see there is a reference to "DesktopMonitor2" but not sure how to use it in this context ?
$Bitmap1 = '\\server\netlogon\Kix2EXE\Wall800.bmp'
$Bitmap2 = '\\server\netlogon\Kix2EXE\Wall1024.bmp'
$Bitmap3 = '\\server\netlogon\Kix2EXE\Wall1280.bmp'
FUNCTION DoWall($HKCU)
? "Setting HKCU Wallpaper to " + $HKCU + "..." ?
$=WriteValue("HKCU\Control Panel\Desktop","Wallpaper","",REG_SZ)
$WallpaperMode = "1"
$=WriteValue("HKCU\Control Panel\Desktop","Wallpaper","$HKCU",REG_SZ)
$=WriteValue("HKCU\Control Panel\Desktop","WallpaperStyle","2",REG_SZ)
$=WriteValue("HKCU\Control Panel\Desktop","TileWallpaper","0",REG_SZ)
$=SetWallpaper($HKCU, $WallpaperMode)
ENDFUNCTION
$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 = "800x600"
DoWall ($Bitmap1)
case $screenres1 = "1024x768"
DoWall ($Bitmap2 )
case $screenres1 = "1280x800"
DoWall ($Bitmap3)
case 1
? "No standard screen resolution detected defaulting to none..................................."
DoWall ($Bitmap2 )
; Must be using some other resolution
endselect
Edited by Mart (2009-07-31 09:03 PM) Edit Reason: Added code tags.
|
Top
|
|
|
|
#195145 - 2009-07-30 05:44 PM
Re: Dual monitors using UDF
[Re: Gargoyle]
|
Radimus
Moderator
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
firstly this is probably the most efficient method:
$wmiColl = GetObject("WinMgmts:root/cimv2").ExecQuery("Select * FROM Win32_DesktopMonitor")
For Each $wmiObj In $wmiColl
if $wmiObj.PNPDeviceID > ' '
$res = CSTR($wmiObj.ScreenWidth)
$nul = setwallpaper('\\server\netlogon\Kix2EXE\Wall'+$res+'.bmp',$WallpaperMode)
endif
Next
Second, it will work because: you cannot set a different wallpaper per monitor people can have monitors with different resolutions
|
Top
|
|
|
|
#195186 - 2009-07-31 05:44 PM
Re: Dual monitors using UDF
[Re: Radimus]
|
xempa
Fresh Scripter
Registered: 2006-08-12
Posts: 37
|
Hi Radimus yes that does makes sense using $res to get the width size and applying it to the name of the bitmap is certainly cleaner and faster. But how do you tell this script to use a default wallpaper in the event the wallpaper doesn't exist ?
Many thanks
I've tried to use a an if statement as below
$Bitmap = '\\Server\netlogon\Kix2EXE\Wall'
FUNCTION DoWall($HKCU)
? "Setting HKCU Wallpaper to " + $HKCU + "..." ?
$=WriteValue("HKCU\Control Panel\Desktop","Wallpaper","",REG_SZ)
$WallpaperMode = "1"
$=WriteValue("HKCU\Control Panel\Desktop","Wallpaper","$HKCU",REG_SZ)
$=WriteValue("HKCU\Control Panel\Desktop","WallpaperStyle","2",REG_SZ)
$=WriteValue("HKCU\Control Panel\Desktop","TileWallpaper","0",REG_SZ)
$=SetWallpaper($HKCU, $WallpaperMode)
ENDFUNCTION
$wmiColl = GetObject("WinMgmts:root/cimv2").ExecQuery("Select * FROM Win32_DesktopMonitor")
For Each $wmiObj In $wmiColl
$res = CSTR($wmiObj.ScreenWidth)
DoWall('$BitMap'+$res+'.bmp')
Next
e.g I've tried the following but cannot capture the value of $res at this point
$wmiColl = GetObject("WinMgmts:root/cimv2").ExecQuery("Select * FROM Win32_DesktopMonitor")
if not exits ('$BitMap'+$res+'.bmp')
DoWall($BitMap"Default.bmp")
Else
For Each $wmiObj In $wmiColl
$res = CSTR($wmiObj.ScreenWidth)
DoWall('$BitMap'+$res+'.bmp')
Next
Endif
Edited by Mart (2009-07-31 09:01 PM) Edit Reason: Added code tags.
|
Top
|
|
|
|
#195215 - 2009-08-01 11:56 PM
Re: Dual monitors using UDF
[Re: Mart]
|
xempa
Fresh Scripter
Registered: 2006-08-12
Posts: 37
|
Hi many thanks to all particuarly Radimus. The solution that works for me is as follows.
Apologies Mart, if this code is not in the code tag area,I can't see any option to choose this with a response
$wmiColl = GetObject("WinMgmts:root/cimv2").ExecQuery("Select * FROM Win32_DesktopMonitor") For Each $wmiObj In $wmiColl if $wmiObj.PNPDeviceID > ' ' $res = CSTR($wmiObj.ScreenWidth) DoWall($Bitmap1) Endif $res = CSTR($wmiObj.ScreenWidth) if exist('$BitMap'+$res+'.bmp') DoWall('$BitMap'+$res+'.bmp') Else DoWall($Bitmap1) Endif Next
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 507 anonymous users online.
|
|
|