Home > Scrapbook > Auto-Selecting Logon Background

Auto-Selecting Logon Background

Useful for Windows workstations that have differing screen resolutions
By 26/10/10 [Last Edited by Joseph 03/12/10]
BOOKMARK
LOGIN
REGISTER
Thought this may be useful. The VBScript is to be run at startup by the 'Startup Scripts' option in GPO. It detects the resolution of the screen, copies the appropriate file off a network share, and sets it to be the logon background.

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
Next
inFile = "\\srv1\NETLOGON\deskimg\"& intHorizontal & intVertical & ".bmp"

Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oShell = CreateObject("Wscript.Shell")
winDir = oShell.ExpandEnvironmentStrings("%SYSTEMROOT%")
destFile = winDir & "\deskimg.bmp"

If oFSO.FileExists(inFile) and oFSO.FileExists(destFile) Then
	oFSO.DeleteFile destFile
	oFSO.CopyFile inFile, destFile, OVERWRITE_EXISTING
ElseIf oFSO.FileExists(inFile) Then
	oFSO.CopyFile inFile, destFile, OVERWRITE_EXISTING
End If

oShell.RegWrite "HKEY_USERS\.DEFAULT\Control Panel\Desktop\Wallpaper", destFile, "REG_SZ"
oShell.RegWrite "HKEY_USERS\.DEFAULT\Control Panel\Desktop\WallPaperStyle", "2", "REG_SZ"
oShell.RegWrite "HKEY_USERS\.DEFAULT\Control Panel\Desktop\TileWallpaper", "0", "REG_SZ"

Change \\srv1\NETLOGON\deskimg\ to the path containing images (remember to leave a trailing \)
Images are in the format XY.BMP (e.g. 1024768.bmp)
You can change this if you wish to allow other filetypes etc.

Wrote/pieced this together as all my computers have different screen resolutions, so I couldn't use 1 common image.