Setting desktop wallpaper
Group Policy will, by default, only set the desktop wallpaper using Active Desktop. It is also possible to set the wallpaper using the logon script, or using a custom Group Policy template.
Custom Group Policy Template
The first thing to note about the custom policy is that it is an Unmanaged Policy. That means that any setting change will not revert if the policy is set to Disabled or Not Configured. The setting would have to be manually reversed or removed.
The second thing to note is that Unmanaged Policies are not displayed by default. After adding this template select the Administrative Templates folder under User Configuration, then View and Filtering. Remove the tick from “Show only policy settings that can be fully managed”. The policy will appear with a red icon instead of the regular blue icon.
This is a template that can be used to set the wallpaper on a client. It must be saved as a Administrative Template (.adm) file and manually added into a policy.
CLASS USER
CATEGORY "Desktop"
CATEGORY "Custom Policies"
KEYNAME "Control Panel\Desktop"
POLICY "Desktop Wallpaper"
EXPLAIN !!ExplainText
PART !!WallpaperPathText EDITTEXT REQUIRED
VALUENAME "Wallpaper"
END PART
PART !!WallpaperStyleText DROPDOWNLIST
VALUENAME "WallpaperStyle"
ITEMLIST
NAME "Centre" VALUE NUMERIC 0 DEFAULT
NAME "Stretch" VALUE NUMERIC 2
END ITEMLIST
END PART
PART !!TileWallpaperText DROPDOWNLIST
VALUENAME "TileWallpaper"
ITEMLIST
NAME "No" VALUE NUMERIC 0 DEFAULT
NAME "Yes" VALUE NUMERIC 1
END ITEMLIST
END PART
END POLICY
END CATEGORY
END CATEGORY
[Strings]
ExplainText="Specifies the desktop background (wallpaper) displayed on all users' desktops.\n\nThe wallpaper image must be in bitmap (bmp) format.\n\nTo use this setting, type the fully qualified path and name of the file that stores the wallpaper image. You can type a local path, such as C:\Windows\web\wallpaper\home.bmp or a UNC path, such as \\Server\Share\Corp.bmp. If the specified file is not available when the user logs on, no wallpaper is displayed. You can also use this setting to specify that the wallpaper image be centered, tiled, or stretched.\n\nTo set wallpaper to Centre Tile must be disabled. To set wallpaper to Tiled both Centre and Tiled must be selected."
WallpaperPathText="Full UNC or path to Bitmap (bmp) file:"
WallpaperStyleText="Centre or Stretch Wallpaper:"
TileWallpaperText="Tile Wallpaper (if centre is selected):"
VbScript
Alternatively, the same registry entries can be set using VbScript. This has the potential to be more flexible depending on the environment. It will run under a standard user, no need to grant extra rights on the PC.
Option Explicit
' Network and local locations for the wallpaper file.
' Must be BMP for the screen refresh to work
Const WALLPAPER_SOURCE = "\\server01\netlogon\Wallpaper.bmp"
Sub SetWallpaper
' Copies and sets the client wallpaper
Const REG_HKCU = &H80000001
Dim objShell, objFileSystem, objFile, objRegistry
Dim strWallpaperDestination, strKeyPath, strCommand
' Get the current user profile so we can copy the wallpaper there.
Set objShell = CreateObject("WScript.Shell")
strWallpaperDestination = objShell.ExpandEnvironmentStrings("%USERPROFILE%")
' Get the wallpaper file from the source
Set objFileSystem = CreateObject("Scripting.FileSystemObject")
Set objFile = objFileSystem.GetFile(WALLPAPER_SOURCE)
' Update the destination path to include the file name
strWallpaperDestination = strWallpaperDestination & "\" & objFile.Name
objFile.Copy strWallpaperDestination, True
Set objFileSystem = Nothing
' Connect to the Registry on the local machine
Set objRegistry = GetObject("winmgmts:\\.\root\default:StdRegProv")
' Set the values for the Wallpaper
strKeyPath = "Control Panel\Desktop"
objRegistry.SetStringValue REG_HKCU, strKeyPath, "Wallpaper", _
strWallpaperDestination
' Set the Position to Stretch
objRegistry.SetStringValue REG_HKCU, strKeyPath, "TileWallpaper", "0"
objRegistry.SetStringValue REG_HKCU, strKeyPath, "WallpaperStyle", "2"
Set objRegistry = Nothing
' Update the system settings (refresh)
strCommand = "RUNDLL32.EXE user32.dll,UpdatePerUserSystemParameters"
objShell.Run strCommand, 1, True
Set objShell = Nothing
End Sub
SetWallpaper
Random wallpaper with VbScript
I once had to deploy one of a selection of wallpapers to client computers on a network. It had to change (or at least attempt to change) each time the user logged on. This snippet uses the Randomize function in VbScript to generate a random number and pick a random file.
Option Explicit
Sub SetWallpaper
' Copies and sets the client wallpaper
Const REG_HKCU = &H80000001
Dim objShell, objFileSystem, objFile, objRegistry
Dim strWallpaperSource, strWallpaperDestination, strKeyPath, strCommand
' Get the current user profile so we can copy the wallpaper there.
Set objShell = CreateObject("WScript.Shell")
strWallpaperDestination = objShell.ExpandEnvironmentStrings("%USERPROFILE%")
' Get the source path
strWallpaperSource = RandomizeWallpaper
' Get the wallpaper file from the source
Set objFileSystem = CreateObject("Scripting.FileSystemObject")
Set objFile = objFileSystem.GetFile(strWallpaperSource)
' Update the destination path to include the file name
strWallpaperDestination = strWallpaperDestination & "\" & objFile.Name
objFile.Copy strWallpaperDestination, True
Set objFileSystem = Nothing
' Connect to the Registry on the local machine
Set objRegistry = GetObject("winmgmts:\\.\root\default:StdRegProv")
' Set the values for the Wallpaper
strKeyPath = "Control Panel\Desktop"
objRegistry.SetStringValue REG_HKCU, strKeyPath, "Wallpaper", strWallpaperDestination
' Set the Position to Stretch
objRegistry.SetStringValue REG_HKCU, strKeyPath, "TileWallpaper", "0"
objRegistry.SetStringValue REG_HKCU, strKeyPath, "WallpaperStyle", "2"
Set objRegistry = Nothing
' Update the system settings (refresh)
strCommand = "RUNDLL32.EXE user32.dll,UpdatePerUserSystemParameters"
objShell.Run strCommand, 1, True
Set objShell = Nothing
End Sub
Function RandomizeWallpaper
Dim objShell, objFolder, objSubFolder, objFile
Dim strLogonServer
Dim arrWallpaper()
Dim i
' Get the current user profile so we can copy the wallpaper there.
Set objShell = CreateObject("WScript.Shell")
strLogonServer = objShell.ExpandEnvironmentStrings("%LOGONSERVER%")
Set objShell = Nothing
Set objFolder = objFileSystem.GetFolder(strLogonServer & "\NetLogon\Wallpaper")
i = 0
' Get all the files beneath the folder
For Each objFile in objFolder.Files
ReDim Preserve arrWallpaper(i)
arrWallpaper(i) = objFile.Path
i = i + 1
Next
Randomize()
' Choose a random file
i = Int(UBound(arrWallpaper) * Rnd())
RandomizeWallpaper = arrWallpaper(i)
End Function
SetWallpaper
Related posts:
- Listing Trusts A script to enumerate trust information from an Active Directory...
Related posts brought to you by Yet Another Related Posts Plugin.
Respond to this post