<

[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x

How to apply a dynamic background via Active Directory GPP

Published on
6,078 Points
678 Views
4 Endorsements
Last Modified:
Shaun Vermaak
My name is Shaun Vermaak and I have always been fascinated with technology and how we use it to enhance our lives and business.
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display

Step 1 - Creating Backgrounds

Designing backgrounds are out of scope for this article but a few guidelines are listed below

Using information from https://en.wikipedia.org/wiki/Display_resolution we can conclude that we mainly need to cater for 16:9, 16:10, 4:3 and 5:4 aspect ratios with a maximum width of 7680px.

If the required background is mainly horizontal, use this guide to create four different versions of background image
ScreenResolutions.jpgAlternatively, if the image is mainly vertical, start with a 10 924px x 6144px image and crop to create four different versions of background image
ScreenRatios.png
 

Step 2 - User Environmental Variables

After creating the four different versions of the background, we need a way to control which version of background is pushed to the computers.

Create four user environmental variable objects using GPO User Environmental Preferences

1.png2.png3.png4.pngHere is the values required to create the four entries
  • 16:9 - PrimaryScreenAspectRatio = 1.778

    • Select * from Win32_DesktopMonitor where ScreenWidth='1280' and ScreenHeight='720'
    • Select * from Win32_DesktopMonitor where ScreenWidth='1600' and ScreenHeight='900'
    • Select * from Win32_DesktopMonitor where ScreenWidth='1920' and ScreenHeight='1080'
    • Select * from Win32_DesktopMonitor where ScreenWidth='2560' and ScreenHeight='1440'
    • Select * from Win32_DesktopMonitor where ScreenWidth='3840' and ScreenHeight='2160'
    • Select * from Win32_DesktopMonitor where ScreenWidth='7680' and ScreenHeight='4320'
  • 16:10 PrimaryScreenAspectRatio = 1.6
    • Select * from Win32_DesktopMonitor where ScreenWidth='1280' and ScreenHeight='800'
    • Select * from Win32_DesktopMonitor where ScreenWidth='1440' and ScreenHeight='900'
    • Select * from Win32_DesktopMonitor where ScreenWidth='1680' and ScreenHeight='1050'
    • Select * from Win32_DesktopMonitor where ScreenWidth='1920' and ScreenHeight='1200'
    • Select * from Win32_DesktopMonitor where ScreenWidth='2560' and ScreenHeight='1600'
  • 4:3 PrimaryScreenAspectRatio = 1.333
    • Select * from Win32_DesktopMonitor where ScreenWidth='320' and ScreenHeight='200'
    • Select * from Win32_DesktopMonitor where ScreenWidth='640' and ScreenHeight='480'
    • Select * from Win32_DesktopMonitor where ScreenWidth='800' and ScreenHeight='600'
    • Select * from Win32_DesktopMonitor where ScreenWidth='1024' and ScreenHeight='768'
    • Select * from Win32_DesktopMonitor where ScreenWidth='1152' and ScreenHeight='864'
    • Select * from Win32_DesktopMonitor where ScreenWidth='1600' and ScreenHeight='1200'
  • 5:4 PrimaryScreenAspectRatio = 1.25
    • Select * from Win32_DesktopMonitor where ScreenWidth='1280' and ScreenHeight='1024
A C# application can be deployed as an addition to the GPO User Environmental Variables Preference Items as a GPO User File Preference. This is useful on RDP sessions and Hyper-V consoles where the WMI objects are not populated properly.
 
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace SetXRes
{
    class Program
    {
        static void Main(string[] args)
        {

            double primaryScreenAspectRatio;
            Rectangle resolution = Screen.PrimaryScreen.Bounds;
            primaryScreenAspectRatio = Math.Round(((double)resolution.Width / (double)resolution.Height), 3);

            Console.WriteLine(resolution.Width);
            Console.WriteLine(resolution.Height);
            Console.WriteLine(primaryScreenAspectRatio.ToString().Replace(',', '.'));

            Environment.SetEnvironmentVariable("PrimaryScreenAspectRatio", primaryScreenAspectRatio.ToString().Replace(',','.'), EnvironmentVariableTarget.User);
        }
    }
}

Open in new window

 

Step 3 - Background File Deployment
Create four file objects using GPO User Files Preferences

Based on the User Environmental Variable set in the previous step, an appropriately ratioed background file will be pushed to computers
5.png6.png7.png8.pngHere is the values required to create the four entries
  • 16:9 - Source file(s) \\YOURDOMAIN.com\NETLOGON\Backgrounds\16-9.PNG

    • the environment variable %PrimaryScreenAspectRatio% is 1.778
  • 16:10 Source file(s) \\YOURDOMAIN.com\NETLOGON\Backgrounds\16-10.PNG
    • the environment variable %PrimaryScreenAspectRatio% is 1.6
  • 4:3 16:10 Source file(s) \\YOURDOMAIN.com\NETLOGON\Backgrounds\4-3.PNG
    • the environment variable %PrimaryScreenAspectRatio% is 1.333
  • 5:4 16:10 Source file(s) \\YOURDOMAIN.com\NETLOGON\Backgrounds\5-4.PNG
    • the environment variable %PrimaryScreenAspectRatio% is 1.25
The target file for all of these entries is %AppDataDir%\Branding\Background\Background.png

Step 4 - Applying Background

Now for the easy bit, just configure the background %AppData%\Branding\Background\Background.png.
Because the background is dynamically assigned, it will always have the same path on the computers

9.png10.pngPlease do not forget to press the "Thumb's Up" button if this article was helpful and valuable for EE members.
It also provides me with positive feedback. Thank you!
4
Comment
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 3

Expert Comment

by:alohadin
This has been bookmarked!
Great stuff Shaun.
Thanks a lot.
1
 
LVL 8

Expert Comment

by:Senior IT System Engineer
thanks for sharing such a great article Shaun :-) !
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Join & Write a Comment

Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

Keep in touch with Experts Exchange

Tech news and trends delivered to your inbox every month