set desktop wallpaper based on screen resolution for both WinXP and Win7
-
Sunday, January 09, 2011 3:37 PM
I'm hoping someone can answer this for me. I would like to be able to set the desktop wallpaper based on the current screen resolution when a user logs in. I've made several .BMP files for varying resolutions with our corporation logo. But, say if a wallpaper for a resolution of 1024x768 on a 4:3 monitor is set, then that monitor is replaced with a 16:10 monitor with a resolution of 1280x800 or 1600x900, the wallpaper looks stretched out and ugly. The only way to change it is manually on each computer, but most end users (students) would not have permissions to do so.
I thought this question would have been asked before, but after many, many searches, I've only come across one reference that copies the background from a network share to a location on the local computer, which I found here. In my case, the file will already be on the local computer, but I am not sure how to force the system to change the wallpaper based on the current screen resolution. I'm sure it is possible and maybe I am overlooking something very simple. I was also thinking that this would either happen only once on first login or maybe based on user authentication (which group the user belongs to) so that teachers are still able to change their wallpaper, but students would not be able to.
If it helps, I will be deploying the image using MDT 2010 Update 1. The same base image will be used on multiple machine types (HP desktop sand laptops and Lenovo desktops) which could have one of 6-7 different monitor types connected. I'd also like this to happen on the local machine instead of GPO or logon script as there is already a lot happening there.
I would need to be able to do this for both Windows XP Pro and Windows 7 Ent x64. The XP machines will mostly have 4:3 monitors, but there are exceptions.
Maybe what I am asking isn't entirely possible or possible at all. I, unfortunately, am in the extremely early stages of learning Microsoft Scripting (VBScript and PowerShell) to use with MDT 2010, so I know next to nothing when it comes to these scripting processes, but am willing to try and learn.
Any help anyone can suggest, I would be extremely grateful.
All Replies
-
Sunday, January 09, 2011 6:48 PM
Perhaps this could work? My problem is that i can't get the if statement to tag the screenheight value.. not complete but perhaps one of the many gurus here can make a suggestion :)
$desktop = Get-WmiObject -Class Win32_DesktopMonitor
Function Set-WallPaper($Value)
{
Set-ItemProperty -path 'HKCU:\Control Panel\Desktop\' -name wallpaper -value $value
rundll32.exe user32.dll, UpdatePerUserSystemParameters
}if ($dekstops.ScreenHeight -eq 1200){set-wallpaper -value path to wallpaper}
-
Sunday, January 09, 2011 8:37 PMModerator
Klorgas,
Have you tried pulling the ScreenHeight property just by itself to see if it matches? Trying the code below worked perfectly for pulling height and width information for my machine.
$Resolution = Get-WMIObject -class Win32_DesktopMonitor
$Resolution.ScreenHeight
$Resolution.ScreenWidthDo you get an error when you enter the if block? Myself I prefer not to seperate my code into functions for a single script unless it will improve readability or code resuse. In this case I think it is more likely that this code segment would be a single use for the script.
mtarggart,
My suggestion is to create two very high resolution JPEG images at high quality and low compression for each aspect ration, rather than one for each resolution. Then just determine which aspect ration is being used, and select widescreen or standard and stretch to fit. This would limit the need for constantly changing the background out when a resolution changes, only when the aspect ratio changes. This means that instead of you managing your backgrounds, Windows handles more of the load. If you are looking to manage the backgrounds though, I would need to know if you have group policies in place that limit the ability of the user to change the background. Let me know about this and I can see what more I can do to help, best of luck!
-
Sunday, January 09, 2011 9:42 PM
I have finally found the registry settings for screen resolution. My thoughts are to querry the settings and then have the script choose the appropriate background based on that querry. This is actually pretty similar to some stuff I am doing. I am gonna work on a script for ya, mtarggart.
It will be for XP Pro, I do not have Windows 7.
HKEY_CURRENT_CONFIG\System\CurrentControlSet\Control\VIDEO\{AD7D81E8-E55E-48BC-81D3-08D35B9568D9}\0000
I am guessing the last part of that key will be different on all the machines though so I will have to use previously suggested: ie Klorgas
Thx Klorgas
Student -
Sunday, January 09, 2011 11:50 PM
'***********************************************************************************************
'This is from: http://geekshangout.com/?q=node/61
'***********************************************************************************************array_ScreenRes = GetScreenResolution
screenRes_X = array_ScreenRes(0)
screenRes_Y = array_ScreenRes(1)
wscript.echo "Resolution is: " & screenRes_X & " by " & screenRes_Y
Function GetScreenResolution()
Set oIE = CreateObject("InternetExplorer.Application")
With oIE
.Navigate("about:blank")
Do Until .readyState = 4: wscript.sleep 100: Loop
width = .document.ParentWindow.screen.width
height = .document.ParentWindow.screen.height
End With
oIE.Quit
GetScreenResolution = array(width,height)
End Function
'************************************************************************************************
'* And this one is from: http://www.visualbasicscript.com/tm.aspx?m=33901
'************************************************************************************************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
NextOk, to change the desktop background we know that this works:
Dim wp
Set wshShell = WScript.CreateObject("WScript.Shell")
sUserName = wshShell.ExpandEnvironmentStrings("admin")
Set oShell = CreateObject("WScript.Shell")
Set oFSO = CreateObject("Scripting.FileSystemObject")
sWinDir = oFSO.GetSpecialFolder(0)
wp = "path to.bmp"oShell.RegWrite "HKCU\Control Panel\Desktop\Wallpaper", wp
oShell.Run "d:\WINDOWS\system32\rundll32.exe user32.dll,UpdatePerUserSystemParameters", 1, TrueSo what is left is to somehow script a decision for which wp path to use. How do you set a variable according to info in a text file. We can write the info to a text file. We can even write scripts to write scripts. So, I wish I were the expert and could blurt out the answer off the top of my head but..... Is my thinking here on the right track. Sorry to answer a question with a question but I am hoping to see some more responses on your post.
Hope this helps
Student- Marked As Answer by Thiyagu14Moderator Saturday, January 29, 2011 7:35 PM
-
Wednesday, January 12, 2011 4:11 PM
Hi Pagerwho,
While reading over your suggestion, I just happen to remember that forgot to mention that we also have laptops (HP ProBook 6445b) that use a 16:9 aspect ratio screen as well as other HP laptops that use a 16:10 aspect ratio. So I would need to make three high res JPEG images, correct?
So, we have desktops using both XP Pro SP3 with 4:3 and 16:10 monitors, desktops using Win 7 Ent x64 using only 16:10 monitors, laptops using Win 7 Ent x64 with both 16:9 and 16:10 screen aspect ratios. My hope is that the 4:3 monitors will begin to be phased out and when a 16:10 monitor is dropped in, the background would change when the resolution changes so it doesn't have to be manually set on 100's, if not 1000's of computers.
Also, I guess what I was thinking of doing was using the backgroud image that I made of say the 1280x800 resolution and that same image on other resolutions of the same aspect ratio. If I follow you right, that is what you were saying to do anyway. So, once it was determined what resolution was being used, it would set one of three background images that would work with that resolution. Does that make sense?
-
Wednesday, January 12, 2011 4:19 PM
MkShffr,
I think the second script may work better, but I'll try to find some free time and mess around with everything that everone has posted so far and see what comes up. If I find anything definite, I'll be sure to post back.
A big THANKS to all who have answered so far. I really didn't expect to get more than one reply.
-
Monday, February 07, 2011 9:36 PM
I almost abandoned this because I thought it was going to interfere with using BGInfo. But, as it turns out, I was able to incorporate the running of BGInfo into a script that I created. And, once I saw what 16:10 Aspect Ratio background looked like on a 16:9 Aspect Ratio screen, I was not satisfied.
I happened to use the first script that MkShffr posted from geekshangout.com, but then I added more items to it. I also created three high-res wallpaper backgrounds as suggested by pagerwho.
My script is based on the Aspect Ratio of the current resolution. Since most, if not all, systems will get the resolution set during deployment, this was easy to calculate. And by forcing the output of the Aspect Ratio to two decimal places, I just used a Case statement to select which aspect ratio to choose from and apply the wallpaper assigned to it. I thought about using If Then statements, but I think the Case statement is much cleaner.
And, because BGInfo wants to change the Picture Position to "Tile" instead of "Fit" that I manually set it to in my image, I added two reg key change lines per Case. BGInfo still changes the Picture Position to "Tile", but for whatever reason, this works. I tested this by using a laptop with a 16:9 Aspect Ratio screen. In my image, I manually set a 16:10 wallpaper because that will be the primary Aspect Ratio used in our corporation, however we are getting more 16:9 Aspect Ratio laptops and from what HP is saying, everything will be standardizing on this Aspect Ratio.
I made sure the Screen profile that I saved in my image was loaded which includes the 16:10 wallpaper. I then placed this script in the “C:\ProgramData\Wallpaper_Change” directory that I created in the image. I then added a registry value in HKLM\System\Microsoft\Windows\CurrentVersion\Run and created a String Value. I did this so that it would run at log in, but I didn't want it to show in the Startup Folder in the All Programs Menu. It takes less than a second to run, but it seems to work well. I tested it several time to see if there were any anomalies, but it seemed to work great each time. I have yet to test it with a computer that is on the domain with a regular user account, which I will be doing in the next day or two.
In the mean time, if someone want to try it out and see if it works from thier use, here is the code. I did comment out the wscript.echos, but left them in to use for troubleshooting in the future.
-Mike
==============================
Option Explicit
Dim array_ScreenRes, screenRes_X, screenRes_Y, oIE, width, height, aspect_ratio
Dim decpos, wallpaper1, wallpaper2, wallpaper3, oShellarray_ScreenRes = GetScreenResolution
screenRes_X = array_ScreenRes(0)
screenRes_Y = array_ScreenRes(1)
wallpaper1="C:\Windows\Web\Wallpaper\TSC\Win 7 - 2560 x 1440 (16-9)TSC.bmp"
wallpaper2="C:\Windows\Web\Wallpaper\TSC\Win 7 - 2560 x 1600 (16-10)TSC.bmp"
wallpaper3="C:\Windows\Web\Wallpaper\TSC\Win 7 - 2560 x 1920 (4-3)TSC.bmp"Set oShell = CreateObject("Wscript.Shell")
'wscript.echo "Resolution is " & screenRes_X & "x" & screenRes_Y
aspect_ratio = screenRes_X/screenRes_Ydecpos=instr(aspect_ratio,".")+2
aspect_ratio=left(aspect_ratio,decpos)'wscript.echo "Aspect Ratio is " & aspect_ratio
Select Case aspect_ratio
Case "1.77"
oShell.RegWrite("HKCU\Control Panel\Desktop\Wallpaper"), wallpaper1
oShell.RegWrite("HKCU\Software\Microsoft\Internet Explorer\Desktop\General\WallpaperSource"), wallpaper1
oShell.RegWrite("HKCU\Control Panel\Desktop\TileWallpaper"), "0"
oShell.RegWrite("HKCU\Control Panel\Desktop\WallpaperStyle"), "6"
Case "1.6"
oShell.RegWrite("HKCU\Control Panel\Desktop\Wallpaper"), wallpaper2
oShell.RegWrite("HKCU\Software\Microsoft\Internet Explorer\Desktop\General\WallpaperSource"), wallpaper2
oShell.RegWrite("HKCU\Control Panel\Desktop\TileWallpaper"), "0"
oShell.RegWrite("HKCU\Control Panel\Desktop\WallpaperStyle"), "6"
Case "1.33"
oShell.RegWrite("HKCU\Control Panel\Desktop\Wallpaper"), wallpaper3
oShell.RegWrite("HKCU\Software\Microsoft\Internet Explorer\Desktop\General\WallpaperSource"), wallpaper3
oShell.RegWrite("HKCU\Control Panel\Desktop\TileWallpaper"), "0"
oShell.RegWrite("HKCU\Control Panel\Desktop\WallpaperStyle"), "6"
End Select
oShell.Run "%windir%\System32\RUNDLL32.exe user32.dll,UpdatePerUserSystemParameters", 1, TrueoShell.Run "C:\ProgramData\BGInfo\BGInfo.exe C:\ProgramData\BGInfo\TSC.bgi /timer:0"
Function GetScreenResolution()
Set oIE = CreateObject("InternetExplorer.Application")
With oIE
.Navigate("about:blank")
Do Until .readyState = 4: wscript.sleep 100: Loop
width = .document.ParentWindow.screen.width
height = .document.ParentWindow.screen.height
End With
oIE.Quit
GetScreenResolution = array(width,height)
End Function -
Thursday, May 19, 2011 12:49 PM
Even if this is an old post I took the liberty to modify your script a little ;)
This way it works regardless of the system locale (some locales have a , instead of . as a separator for floats)
'----------------------------------------------------------------------------------------
'Constants And Variables
'----------------------------------------------------------------------------------------
On Error Resume Next
Dim array_ScreenRes, screenRes_X, screenRes_Y, oIE, width, height, aspect_ratio
Dim decpos, oShell, wallpaper
Set oShell = CreateObject("Wscript.Shell")
'----------------------------------------------------------------------------------------
'General 1 - Main script processing area
'----------------------------------------------------------------------------------------
array_ScreenRes = GetScreenResolution
screenRes_X = array_ScreenRes(0)
screenRes_Y = array_ScreenRes(1)aspect_ratio = (screenRes_X/screenRes_Y*100)\1
'determine aspect ratio with two digits after the comma in a locale insensitive way
Select Case aspect_ratio
Case "177"
wallpaper="C:\Windows\Web\Wallpaper\Windows_7_Wallpaper_16_to_09.bmp"
Case "160"
wallpaper="C:\Windows\Web\Wallpaper\Windows_7_Wallpaper_16_to_10.bmp"
Case "133"
wallpaper="C:\Windows\Web\Wallpaper\Windows_7_Wallpaper_04_to_03.bmp"
End SelectoShell.RegWrite("HKCU\Control Panel\Desktop\Wallpaper"), wallpaper
oShell.RegWrite("HKCU\Software\Microsoft\Internet Explorer\Desktop\General\WallpaperSource"), wallpaper
oShell.RegWrite("HKCU\Control Panel\Desktop\TileWallpaper"), "0"
oShell.RegWrite("HKCU\Control Panel\Desktop\WallpaperStyle"), "6"
oShell.Run "%windir%\System32\RUNDLL32.exe user32.dll,UpdatePerUserSystemParameters", 1, True
'----------------------------------------------------------------------------------------
'Functions and subs
'----------------------------------------------------------------------------------------
'Function 1 - Get Screen Resolution
'----------------------------------------------------------------------------------------
Function GetScreenResolution()
Set oIE = CreateObject("InternetExplorer.Application")
With oIE
.Navigate("about:blank")
Do Until .readyState = 4: wscript.sleep 100: Loop
width = .document.ParentWindow.screen.width
height = .document.ParentWindow.screen.height
End With
oIE.Quit
GetScreenResolution = array(width,height)
End Function

