diff --git a/flash/scripts/07-desktop-info.ps1 b/flash/scripts/07-desktop-info.ps1 index 7c379aa..84f2e7f 100644 --- a/flash/scripts/07-desktop-info.ps1 +++ b/flash/scripts/07-desktop-info.ps1 @@ -31,6 +31,12 @@ $renderContent = @' # Runs on every user logon via Scheduled Task. $ErrorActionPreference = "Continue" +$LogFile = "C:\Windows\Setup\Scripts\desktopinfo.log" +function Write-Log { + param([string]$Message, [string]$Level = "INFO") + Add-Content -Path $LogFile -Value "[$(Get-Date -Format 'HH:mm:ss')] [$Level] $Message" -Encoding UTF8 +} +Write-Log "DesktopInfo render started" -Level INFO Add-Type -AssemblyName System.Drawing Add-Type -AssemblyName System.Windows.Forms @@ -46,6 +52,7 @@ public class WallpaperApi { # ----------------------------------------------------------------------- # Collect system info # ----------------------------------------------------------------------- +Write-Log "Collecting system info" $hostname = $env:COMPUTERNAME $userDomain = $env:USERDOMAIN $userName = $env:USERNAME @@ -69,12 +76,15 @@ $domain = if ($csInfo -and $csInfo.PartOfDomain) { $csInfo.Domain } ` elseif ($csInfo -and $csInfo.Workgroup) { $csInfo.Workgroup.ToLower() } ` else { "N/A" } +Write-Log "hostname=$hostname user=$loggedUser os=$osName ram=$($ramGB)GB cpu=${cpuCount}x${cpuSpeed}MHz ips=$ips domain=$domain" + # ----------------------------------------------------------------------- # Screen dimensions # ----------------------------------------------------------------------- $screen = [System.Windows.Forms.Screen]::PrimaryScreen $width = if ($screen) { $screen.Bounds.Width } else { 1920 } $height = if ($screen) { $screen.Bounds.Height } else { 1080 } +Write-Log "screen=${width}x${height}" # ----------------------------------------------------------------------- # Create bitmap and graphics context @@ -134,11 +144,22 @@ $g.Dispose() # Save and set as wallpaper # ----------------------------------------------------------------------- $bmpPath = "C:\Windows\Setup\Scripts\desktopinfo.bmp" +Write-Log "Saving BMP: $bmpPath" $bmp.Save($bmpPath, [System.Drawing.Imaging.ImageFormat]::Bmp) $bmp.Dispose() +# Clear Windows wallpaper cache so it reloads from our BMP +# Without this, Windows reuses TranscodedWallpaper and ignores the updated file +$transcodedPath = "$env:APPDATA\Microsoft\Windows\Themes\TranscodedWallpaper" +if (Test-Path $transcodedPath) { + Remove-Item $transcodedPath -Force -ErrorAction SilentlyContinue + Write-Log "Cleared TranscodedWallpaper cache" +} + # SPI_SETDESKTOPWALLPAPER=20, SPIF_UPDATEINIFILE|SPIF_SENDCHANGE=3 -[WallpaperApi]::SystemParametersInfo(20, 0, $bmpPath, 3) | Out-Null +$result = [WallpaperApi]::SystemParametersInfo(20, 0, $bmpPath, 3) +Write-Log "SystemParametersInfo result: $result" +Write-Log "DesktopInfo render complete" -Level INFO '@ $renderContent | Set-Content -Path $RenderScript -Encoding UTF8 -Force diff --git a/scripts/07-desktop-info.ps1 b/scripts/07-desktop-info.ps1 index 7c379aa..84f2e7f 100644 --- a/scripts/07-desktop-info.ps1 +++ b/scripts/07-desktop-info.ps1 @@ -31,6 +31,12 @@ $renderContent = @' # Runs on every user logon via Scheduled Task. $ErrorActionPreference = "Continue" +$LogFile = "C:\Windows\Setup\Scripts\desktopinfo.log" +function Write-Log { + param([string]$Message, [string]$Level = "INFO") + Add-Content -Path $LogFile -Value "[$(Get-Date -Format 'HH:mm:ss')] [$Level] $Message" -Encoding UTF8 +} +Write-Log "DesktopInfo render started" -Level INFO Add-Type -AssemblyName System.Drawing Add-Type -AssemblyName System.Windows.Forms @@ -46,6 +52,7 @@ public class WallpaperApi { # ----------------------------------------------------------------------- # Collect system info # ----------------------------------------------------------------------- +Write-Log "Collecting system info" $hostname = $env:COMPUTERNAME $userDomain = $env:USERDOMAIN $userName = $env:USERNAME @@ -69,12 +76,15 @@ $domain = if ($csInfo -and $csInfo.PartOfDomain) { $csInfo.Domain } ` elseif ($csInfo -and $csInfo.Workgroup) { $csInfo.Workgroup.ToLower() } ` else { "N/A" } +Write-Log "hostname=$hostname user=$loggedUser os=$osName ram=$($ramGB)GB cpu=${cpuCount}x${cpuSpeed}MHz ips=$ips domain=$domain" + # ----------------------------------------------------------------------- # Screen dimensions # ----------------------------------------------------------------------- $screen = [System.Windows.Forms.Screen]::PrimaryScreen $width = if ($screen) { $screen.Bounds.Width } else { 1920 } $height = if ($screen) { $screen.Bounds.Height } else { 1080 } +Write-Log "screen=${width}x${height}" # ----------------------------------------------------------------------- # Create bitmap and graphics context @@ -134,11 +144,22 @@ $g.Dispose() # Save and set as wallpaper # ----------------------------------------------------------------------- $bmpPath = "C:\Windows\Setup\Scripts\desktopinfo.bmp" +Write-Log "Saving BMP: $bmpPath" $bmp.Save($bmpPath, [System.Drawing.Imaging.ImageFormat]::Bmp) $bmp.Dispose() +# Clear Windows wallpaper cache so it reloads from our BMP +# Without this, Windows reuses TranscodedWallpaper and ignores the updated file +$transcodedPath = "$env:APPDATA\Microsoft\Windows\Themes\TranscodedWallpaper" +if (Test-Path $transcodedPath) { + Remove-Item $transcodedPath -Force -ErrorAction SilentlyContinue + Write-Log "Cleared TranscodedWallpaper cache" +} + # SPI_SETDESKTOPWALLPAPER=20, SPIF_UPDATEINIFILE|SPIF_SENDCHANGE=3 -[WallpaperApi]::SystemParametersInfo(20, 0, $bmpPath, 3) | Out-Null +$result = [WallpaperApi]::SystemParametersInfo(20, 0, $bmpPath, 3) +Write-Log "SystemParametersInfo result: $result" +Write-Log "DesktopInfo render complete" -Level INFO '@ $renderContent | Set-Content -Path $RenderScript -Encoding UTF8 -Force