<

How to apply a dynamic background via Active Directory GPP

Published on
6,549 Points
849 Views
7 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!
7
Comment
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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Join & Write a Comment

This tutorial will walk an individual through the process of configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

Keep in touch with Experts Exchange

Tech news and trends delivered to your inbox every month