GPO to push different wallpaper files dependant on resolution


Recommended Posts

So we're trying to role out a company wide desktop background. The only problem is we have a few different resolutions running on the network. I've narrowed it down to having two files - a widescreen one and a normal one but I cant see a way to deploy this. Deploying it per usergroup wont work as we have different resolutions there too. Any of you guys come across this before? I'm assuming there must be a script somewhere but i wouldn't know how to check the current resolution etc. 

  On 04/10/2013 at 09:03, Riva said:

You can either create one OU in AD for each device resolution and apply a different GPO for each or use a script to detect the screen resolution and apply the correct wallpaper at logon

Have you any idea of where i can find some documentation on what would need to be included in that script? I would prefer that option as it would be automatic for new machines and not require a new OU. 

  On 04/10/2013 at 09:25, Riva said:

 Detect resolution

strComputer = "."

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set colItems = objWMIService.ExecQuery _
    ("Select * From Win32_DisplayConfiguration")

For Each objItem in colItems
    Wscript.Echo "Name: " & objItem.DeviceName
    Wscript.Echo "Color depth: " & objItem.BitsPerPel
    Wscript.Echo "Horizontal resolution: " & objItem.PelsWidth
    Wscript.Echo "Vertical resolution: " & objItem.PelsHeight
    Wscript.Echo
Next

Change wallpaper using VBScript 

Dim WshShell

 Set WshShell = WScript.CreateObject("Wscript.Shell")
 WshShell.RegWrite "HKCU\Control Panel\Desktop\Wallpaper", mybitmap.bmp
 WshShell.Run "%windir%\System32\RUNDLL32.EXE user32.dll, 
 UpdatePerUserSystemParameters", 1, False

 Set WshShell = Nothing

Sorry I cant quote or paste hyperlinks on this forum as I use IE11. Just google run vbscript via GPO on user logon

Excellent thanks! I'll give this a go :) 

  On 04/10/2013 at 09:25, Riva said:

 Detect resolution

strComputer = "."

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set colItems = objWMIService.ExecQuery _
    ("Select * From Win32_DisplayConfiguration")

For Each objItem in colItems
    Wscript.Echo "Name: " & objItem.DeviceName
    Wscript.Echo "Color depth: " & objItem.BitsPerPel
    Wscript.Echo "Horizontal resolution: " & objItem.PelsWidth
    Wscript.Echo "Vertical resolution: " & objItem.PelsHeight
    Wscript.Echo
Next

Change wallpaper using VBScript 

Dim WshShell

 Set WshShell = WScript.CreateObject("Wscript.Shell")
 WshShell.RegWrite "HKCU\Control Panel\Desktop\Wallpaper", mybitmap.bmp
 WshShell.Run "%windir%\System32\RUNDLL32.EXE user32.dll, 
 UpdatePerUserSystemParameters", 1, False

 Set WshShell = Nothing

Sorry I cant quote or paste hyperlinks on this forum as I use IE11. Just google run vbscript via GPO on user logon

Presumably there needs to be some sort of condition in there? Like if resolution 1280x1024 then use wallpaper1280x1024.jpg?

  • 2 weeks later...

what would i add if i have 4 different resolutions?

 

1024x768

800x600

1280x800

1680x1050

 

would it look like this 

 

If objItem.ScreenWidth > 1024 Then        
        
WshShell.RegWrite "HKCU\Control Panel\Desktop\Wallpaper", "C:\1024.jpg"
If objItem.ScreenWidth > 800 Then        
        
WshShell.RegWrite "HKCU\Control Panel\Desktop\Wallpaper", "C:\800.jpg"
If objItem.ScreenWidth > 1280 Then        
        
WshShell.RegWrite "HKCU\Control Panel\Desktop\Wallpaper", "C:\1280.jpg"   

If objItem.ScreenWidth > 1680 Then        
        
WshShell.RegWrite "HKCU\Control Panel\Desktop\Wallpaper", "C:\1680.jpg"

 Else
        WshShell.RegWrite "HKCU\Control Panel\Desktop\Wallpaper", "C:\normal.jpg"
    End If

 

will this work?

Riva, 

 

in that post i just posted, would i use this instead of a desktop GPO meaning would i just put the script and images in a folder then great a logon script inside the GPO??

 

ideally i would like to run the script once let it determine the image to put out then ignore it moving forward.

 

The real issue that i'm facing is we have 4 images at dif resolutions, i can push out via GPO but the images look streached or messed up...i'm hoping running this script will help me in this situation.

 

Could you chim in to the steps i need to take?

  On 16/10/2013 at 12:30, cgratton said:

what would i add if i have 4 different resolutions?

 

1024x768

800x600

1280x800

1680x1050

 

would it look like this 

 

If objItem.ScreenWidth > 1024 Then        

        WshShell.RegWrite "HKCU\Control Panel\Desktop\Wallpaper", "C:\1024.jpg"If objItem.ScreenWidth > 800 Then        

        WshShell.RegWrite "HKCU\Control Panel\Desktop\Wallpaper", "C:\800.jpg"If objItem.ScreenWidth > 1280 Then        

        WshShell.RegWrite "HKCU\Control Panel\Desktop\Wallpaper", "C:\1280.jpg"   

If objItem.ScreenWidth > 1680 Then        

        WshShell.RegWrite "HKCU\Control Panel\Desktop\Wallpaper", "C:\1680.jpg"

 Else        WshShell.RegWrite "HKCU\Control Panel\Desktop\Wallpaper", "C:\normal.jpg"    End If

 

will this work?

Been a while since I did programming like this and I didn't do much VB(any) but I don't think you can do if/else like that, then you have to nest them. So for multiple resolution you would instead use another function with multiple cases, or you could use nested if's.

  On 15/10/2013 at 20:36, Riva said:
On Error Resume Next
Dim WshShell

Set WshShell = WScript.CreateObject("Wscript.Shell")

strComputer = "."

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_DesktopMonitor",,48)
For Each objItem in colItems 
	If objItem.ScreenWidth > 1024 Then		
		WshShell.RegWrite "HKCU\Control Panel\Desktop\Wallpaper", "C:\wide.jpg"

	Else
		WshShell.RegWrite "HKCU\Control Panel\Desktop\Wallpaper", "C:\normal.jpg"
	End If
	WshShell.Run "%windir%\System32\RUNDLL32.EXE user32.dll, UpdatePerUserSystemParameters", 1, False
Next
Set WshShell = Nothing

Thank you so much! :)

Interesting script, I'd be interesting in knowing how well this works for you +Maximum Error.

 

I tried rolling out a static wallpaper to all my users a while ago through GPO and locked down the Display applet so it couldn't be modified only to find that you could still from within IE set a different wallpaper and override the one specified within the GPO.  Annoyingly so did my users, not that it was a big deal.  Shortly after we abandoned the idea of using a static wallpaper and allowed the to choose their own.

So is this what the entire script looks like?

 

strComputer = "."
 
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
 
Set colItems = objWMIService.ExecQuery _
    ("Select * From Win32_DisplayConfiguration")
 
For Each objItem in colItems
    Wscript.Echo "Name: " & objItem.DeviceName
    Wscript.Echo "Color depth: " & objItem.BitsPerPel
    Wscript.Echo "Horizontal resolution: " & objItem.PelsWidth
    Wscript.Echo "Vertical resolution: " & objItem.PelsHeight
    Wscript.Echo
Next
If objItem.ScreenWidth = 1024 Then        
         WshShell.RegWrite "HKCU\Control Panel\Desktop\Wallpaper", "C:\1024.jpg"
ElseIf objItem.ScreenWidth = 800 Then        
         WshShell.RegWrite "HKCU\Control Panel\Desktop\Wallpaper", "C:\800.jpg"
ElseIf objItem.ScreenWidth = 1280 Then        
         WshShell.RegWrite "HKCU\Control Panel\Desktop\Wallpaper", "C:\1280.jpg"   
 
ElseIf objItem.ScreenWidth = 1680 Then        
         WshShell.RegWrite "HKCU\Control Panel\Desktop\Wallpaper", "C:\1680.jpg"
 
 Else
        WshShell.RegWrite "HKCU\Control Panel\Desktop\Wallpaper", "C:\normal.jpg"
    End If
 
??

When running the script i get and error?

---------------------------
Windows Script Host
---------------------------
Script: C:\Users\cgratton\Desktop\blue.vbs
Line: 15
Char: 1
Error: Object required: 'objItem'
Code: 800A01A8
Source: Microsoft VBScript runtime error
 
---------------------------
OK   
---------------------------

I've done very little with VB over the years but I can see that the conditions aren't in the loop and therefore objitem doesn't exist :P

 

In short move "Next" to the bottom.

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.