;Get the current screen resolution using WMI.
$wmiColl = GetObject("WinMgmts:root/cimv2").ExecQuery("Select * FROM Win32_DesktopMonitor")
For Each $wmiObj in $wmiColl
;Check if the found resolution is for the primary monitor.
If $wmiObj.DeviceID = "DesktopMonitor1"
;Combine width and height.
$screenres = CStr($wmiObj.ScreenWidth) + "x" + CStr($wmiObj.ScreenHeight)
EndIf
Next
;Set wallpaper for regular computers and users.
If Exist(@LDRIVE + "wallpaper\Wallpaper" + $screenres + ".bmp")
;Copy wallpaper from the server when a local copy does not exist.
If Not Exist("C:\localfolder\Wallpaper\Wallpaper" + $screenres + ".bmp")
Copy @LDRIVE + "wallpaper\Wallpaper" + $screenres + ".bmp" "C:\localfolder\Wallpaper\*.*"
Else
;Get the timestamp of the local and remote wallpaper.
$local = GetFileTime("C:\localfolder\Wallpaper\Wallpaper" + $screenres + ".bmp")
$logon = GetFileTime(@LDRIVE + "wallpaper\Wallpaper" + $screenres + ".bmp")
;If the timestamps do not match copy the wallpaper from the server. The server is leading.
If $local <> $logon
Copy @LDRIVE + "wallpaper\Wallpaper" + $screenres + ".bmp" "c:\localfolder\wallpaper\*.*"
EndIf
EndIf
;Set the wallpaper.
$rc = SetWallpaper ("C:\localfolder\Wallpaper\Wallpaper" + $screenres + ".bmp", 1)
;Set the way the wallpaper is displayed.
;Stretched: WallpaperStyle = 2, TileWallpaper = 0.
;Centered: WallpaperStyle = 0, TileWallpaper = 0.
;Tiled: WallpaperStyle = 0, TileWallpaper = 1.
$rc = WriteValue("HKU\" + @SID + "\Control Panel\Desktop", "TileWallpaper", "0", "REG_SZ")
$rc = WriteValue("HKU\" + @SID + "\Control Panel\Desktop", "WallpaperStyle", "2", "REG_SZ")
$rc = WriteValue("HKU\" + @SID + "\Software\Microsoft\Internet Explorer\Desktop\General", "TileWallpaper", "0", "REG_SZ")
$rc = WriteValue("HKU\" + @SID + "\Software\Microsoft\Internet Explorer\Desktop\General", "WallpaperStyle", "2", "REG_SZ")
EndIf