Resources/SplashScreen/Create-FullScreenBackground.ps1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 |
<#
GARY BLOK - Modified script from: SMSAgent https://smsagent.blog/2018/08/21/create-a-custom-splash-screen-for-a-windows-10-in-place-upgrade/ Creates a full screen 'background' styled for a Windows 10 upgrade, and hides the task bar Called by the "Show-OSUpgradeBackground" script Change Log: 23.02.19 - Added Function to read OSDCloud Transcript fields to update Splash Screen #> Param($DeviceName) Start-Transcript x:\OSDCloud\Logs\Splash.log Function Get-LogLastHeading { if ($env:SystemDrive -eq 'X:') { if (Test-Path "C:\OSDCloud\Logs"){$LogsPath = "C:\OSDCloud\Logs"} else {$LogsPath = "X:\OSDCloud\Logs"} $OSDLogFile = Get-ChildItem -Path "$LogsPath\*.log" | Where-Object {$_.Name -match "Deploy-OSDCloud.log"} } $RAWContent = Get-Content $OSDLogFile -ReadCount 1 $StartPoint = $RAWContent | Select-String -SimpleMatch "Transcript started, output" | Select-Object -Property LineNumber $LastRow = $RAWContent | Select-Object -Last 1 $SectionHeadersNumbers = $RAWContent | Select-String -SimpleMatch "====" | Select-Object -Property LineNumber if ($StartPoint){ if ($SectionHeadersNumbers){ $LastHeadersNumbers = $SectionHeadersNumbers | Select-Object -Last 1 $RAWContent[$LastHeadersNumbers.LineNumber + 1] } else { if (($LastRow -notmatch "True") -or ($LastRow -notmatch "global") -and ($LastRow.Length -gt 18)){ $LastRowText = $LastRow.Substring(18) $LastRowtext } else { Write-Output "Working on your OS Installation" } } } } function Get-NetworkStat { #Get-Adapter doesn't work in WinPE properly #$ActiveAdapter = Get-NetAdapter | Where-Object {$_.Status -eq "Up"} | Select-Object -First 1 #[int]$LinkSpeed = $ActiveAdapter.TransmitLinkSpeed $Sample = Get-Counter "\Network Interface(*)\Bytes Total/sec" #needs Windows\System32\pdh.dll added to Boot Media. $SampleValue = ($Sample.CounterSamples | Select-Object -Property CookedValue).CookedValue | Sort-Object -Descending | Select-Object -First 1 #$PercentUtil = [math]::round($SampleValue/($LinkSpeed / 8) * 100) $MBps = [math]::round($SampleValue / 1000000) #Write-Output "MB/s: $MBps | %Util: $PercentUtil" Write-Output "MB/s: $MBps" } if (!($Global:ModuleBase = (Get-Module -Name OSD).ModuleBase)){Import-Module -Name OSD} if ($Global:ModuleBase = (Get-Module -Name OSD).ModuleBase){ $Global:MahAppsPath = "$Global:ModuleBase\Projects\assembly\MahApps.Metro.dll" $Global:InteractivityPath = "$Global:ModuleBase\Projects\assembly\System.Windows.Interactivity.dll" } # Add required assemblies Add-Type -AssemblyName PresentationFramework,PresentationCore,WindowsBase,System.Windows.Forms,System.Drawing Add-Type -AssemblyName System.DirectoryServices.AccountManagement #Add-Type -Path "$PSSCriptRoot\bin\MahApps.Metro.dll" Write-Host "Adding Type MahApps: $Global:MahAppsPath" Add-Type -Path $Global:MahAppsPath #Add-Type -Path "$PSSCriptRoot\bin\System.Windows.Interactivity.dll" Write-Host "Adding Type Interactivity: $Global:InteractivityPath" Add-Type -Path $Global:InteractivityPath # Find screen by DeviceName $Screens = [System.Windows.Forms.Screen]::AllScreens $Screen = $Screens | Where {$_.DeviceName -eq $DeviceName} # Add custom type to hide the taskbar # Thanks to https://stackoverflow.com/questions/25499393/make-my-wpf-application-full-screen-cover-taskbar-and-title-bar-of-window $Source = @" using System; using System.Runtime.InteropServices; public class Taskbar { [DllImport("user32.dll")] private static extern int FindWindow(string className, string windowText); [DllImport("user32.dll")] private static extern int ShowWindow(int hwnd, int command); private const int SW_HIDE = 0; private const int SW_SHOW = 1; protected static int Handle { get { return FindWindow("Shell_TrayWnd", ""); } } private Taskbar() { // hide ctor } public static void Show() { ShowWindow(Handle, SW_SHOW); } public static void Hide() { ShowWindow(Handle, SW_HIDE); } } "@ Add-Type -ReferencedAssemblies 'System', 'System.Runtime.InteropServices' -TypeDefinition $Source -Language CSharp # Find the user identity from the domain if possible Try { $PrincipalContext = [System.DirectoryServices.AccountManagement.PrincipalContext]::new([System.DirectoryServices.AccountManagement.ContextType]::Domain, [System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain()) $GivenName = ([System.DirectoryServices.AccountManagement.Principal]::FindByIdentity($PrincipalContext,[System.DirectoryServices.AccountManagement.IdentityType]::SamAccountName,[Environment]::UserName)).GivenName $PrincipalContext.Dispose() } Catch {} # Create a WPF window $Window = New-Object System.Windows.Window $window.Background = "#012a47" $Window.WindowStyle = [System.Windows.WindowStyle]::None $Window.ResizeMode = [System.Windows.ResizeMode]::NoResize $Window.Foreground = [System.Windows.Media.Brushes]::White $window.Topmost = $True # Get the bounds of the primary screen $Bounds = $Screen.Bounds # Assemble a grid $Grid = New-object System.Windows.Controls.Grid $Grid.Width = "NaN" $Grid.Height = "NaN" $Grid.HorizontalAlignment = "Stretch" $Grid.VerticalAlignment = "Stretch" # Add a column $Column = New-Object System.Windows.Controls.ColumnDefinition $Grid.ColumnDefinitions.Add($Column) # Add rows $Row = New-Object System.Windows.Controls.RowDefinition $Row.Height = "1*" $Grid.RowDefinitions.Add($Row) $Row = New-Object System.Windows.Controls.RowDefinition $Row.Height = [System.Windows.GridLength]::Auto $Grid.RowDefinitions.Add($Row) $Row = New-Object System.Windows.Controls.RowDefinition $Row.Height = [System.Windows.GridLength]::Auto $Grid.RowDefinitions.Add($Row) $Row = New-Object System.Windows.Controls.RowDefinition $Row.Height = "1*" $Grid.RowDefinitions.Add($Row) # Add a progress ring $ProgressRing = [MahApps.Metro.Controls.ProgressRing]::new() $ProgressRing.Opacity = 0 $ProgressRing.IsActive = $false $ProgressRing.Margin = "0,0,0,60" $Grid.AddChild($ProgressRing) $ProgressRing.SetValue([System.Windows.Controls.Grid]::RowProperty,1) # Add a textblock $TextBlock = New-Object System.Windows.Controls.TextBlock If ($GivenName) { $TextBlock.Text = "Hi $GivenName" } Else { $TextBlock.Text = "Hey Team Member" } $TextBlock.TextWrapping = [System.Windows.TextWrapping]::Wrap $TextBlock.MaxWidth = $Bounds.Width $TextBlock.Margin = "0,0,0,120" $TextBlock.FontSize = 50 $TextBlock.FontWeight = [System.Windows.FontWeights]::Light $TextBlock.VerticalAlignment = "Top" $TextBlock.HorizontalAlignment = "Center" $TextBlock.Opacity = 0 $Grid.AddChild($TextBlock) $TextBlock.SetValue([System.Windows.Controls.Grid]::RowProperty,2) # Add a textblock $TextBlock2 = New-Object System.Windows.Controls.TextBlock $TextBlock2.Margin = "0,0,0,60" $TextBlock2.Text = "Don't turn off your PC" $TextBlock2.TextWrapping = [System.Windows.TextWrapping]::Wrap $TextBlock2.MaxWidth = $Bounds.Width $TextBlock2.FontSize = 25 $TextBlock2.FontWeight = [System.Windows.FontWeights]::Light $TextBlock2.VerticalAlignment = "Bottom" $TextBlock2.HorizontalAlignment = "Center" $TextBlock2.Opacity = 0 $Grid.AddChild($TextBlock2) $TextBlock2.SetValue([System.Windows.Controls.Grid]::RowProperty,3) # Add a textblock (@gwblok Change) $TextBlock3 = New-Object System.Windows.Controls.TextBlock $TextBlock3.Margin = "0,0,0,120" $TextBlock3.Text = "Task Sequence Step Should be Here" $TextBlock3.TextWrapping = [System.Windows.TextWrapping]::Wrap $TextBlock3.MaxWidth = $Bounds.Width $TextBlock3.FontSize = 15 $TextBlock3.FontWeight = [System.Windows.FontWeights]::Light $TextBlock3.VerticalAlignment = "Bottom" $TextBlock3.HorizontalAlignment = "Center" $TextBlock3.Opacity = 0 $Grid.AddChild($TextBlock3) $TextBlock3.SetValue([System.Windows.Controls.Grid]::RowProperty,4) # Add a textblock (@gwblok Change) $TextBlock4 = New-Object System.Windows.Controls.TextBlock $TextBlock4.Margin = "0,0,60,60" $TextBlock4.Text = "Downloading..." $TextBlock4.TextWrapping = [System.Windows.TextWrapping]::Wrap $TextBlock4.MaxWidth = $Bounds.Width $TextBlock4.FontSize = 20 $TextBlock4.FontWeight = [System.Windows.FontWeights]::Light $TextBlock4.VerticalAlignment = "Bottom" $TextBlock4.HorizontalAlignment = "Right" $TextBlock4.Opacity = 0 $TextBlock4.Visibility = 'Hidden' $Grid.AddChild($TextBlock4) $TextBlock4.SetValue([System.Windows.Controls.Grid]::RowProperty,5) # Add to window $Window.AddChild($Grid) $FadeinAnimation = [System.Windows.Media.Animation.DoubleAnimation]::new(0,1,[System.Windows.Duration]::new([Timespan]::FromSeconds(3))) $FadeOutAnimation = [System.Windows.Media.Animation.DoubleAnimation]::new(1,0,[System.Windows.Duration]::new([Timespan]::FromSeconds(3))) $ColourBrighterAnimation = [System.Windows.Media.Animation.ColorAnimation]::new("#012a47","#1271b5",[System.Windows.Duration]::new([Timespan]::FromSeconds(5))) $ColourDarkerAnimation = [System.Windows.Media.Animation.ColorAnimation]::new("#1271b5","#012a47",[System.Windows.Duration]::new([Timespan]::FromSeconds(5))) #Looks for SPLASH.JSON files in OSDCloud\Config $Global:SplashScreenJSON = Get-PSDrive -PSProvider FileSystem | Where-Object {$_.Name -ne 'C'} | ForEach-Object { Get-ChildItem "$($_.Root)OSDCloud\Config\" -Include "SPLASH.JSON" -File -Recurse -Force -ErrorAction Ignore } if ($Global:SplashScreenJSON) { Write-Host -ForegroundColor Gray 'OSDCloud Config StartNet Scripts' $Global:SplashScreenJSON = $Global:SplashScreenJSON | Sort-Object -Property FullName $SplashJson = $Global:SplashScreenJSON | Select-Object -Last 1 Write-Host -ForegroundColor Gray "Using $($SplashJson.FullName)" $TextArrayJSON = get-content -Path $SplashJson.FullName | ConvertFrom-Json $TextArray = $TextArrayJSON.TextArray Write-Output $TextArray } # An array of sentences to display, in order. Leave the first one blank as the 0 index gets skipped. if (!($TextArray)){ Write-Host "No Text Array found in JSON, using Defaults" $TextArray = @( "This Line never actually displays" if ($OSVersion -and $OSBuild){"We're installing $OSVersion $OSBuild for you!"} else {"We're installing Windows for you!"} "It may take 60 - 120 minutes" "Your PC will restart several times" "OSDCloud - Good Choice!" "Yes, it's still going!" ) Write-Output $TextArray } $script:i = 0 # Start a dispatcher timer. This is used to control when the sentences are changed. $TimerCode = { $ProgressRing.IsActive = $True # The IF statement number should equal the number of sentences in the TextArray $NumberofElements = $TextArray.Count -1 If ($script:i -lt $NumberofElements) { $FadeoutAnimation.Add_Completed({ $TextBlock.Opacity = 0 $TextBlock.Text = $TextArray[$script:i] $TextBlock.BeginAnimation([System.Windows.Controls.TextBlock]::OpacityProperty,$FadeinAnimation) }) $TextBlock.BeginAnimation([System.Windows.Controls.TextBlock]::OpacityProperty,$FadeoutAnimation) } # The final sentence to display ongoing ElseIf ($script:i -eq $NumberofElements) { $script:i = 0 $FadeoutAnimation.Add_Completed({ $TextBlock.Opacity = 0 $TextBlock.Text = "We're installing Windows on this PC" $TextBlock.BeginAnimation([System.Windows.Controls.TextBlock]::OpacityProperty,$FadeinAnimation) }) $TextBlock.BeginAnimation([System.Windows.Controls.TextBlock]::OpacityProperty,$FadeoutAnimation) } Else { # Restore the taskbar [Taskbar]::Show() # Restore the mouse cursor [System.Windows.Forms.Cursor]::Show() $DispatcherTimer.Stop() $DispatcherTimerTS.Stop() exit } $ColourBrighterAnimation.Add_Completed({ $Window.Background.BeginAnimation([System.Windows.Media.SolidColorBrush]::ColorProperty,$ColourDarkerAnimation) }) $Window.Background.BeginAnimation([System.Windows.Media.SolidColorBrush]::ColorProperty,$ColourBrighterAnimation) $Script:i++ } #Main Text Timer $DispatcherTimer = New-Object -TypeName System.Windows.Threading.DispatcherTimer $DispatcherTimer.Interval = [TimeSpan]::FromSeconds(10) $DispatcherTimer.Add_Tick($TimerCode) #Step Name Timer Controls #Runs at every 1 second to try to make sure it catches all of the step names. $TimerCodeTS = { $TestInfo = Get-LogLastHeading #$TestInfo = $tsenv.Value('_SMSTSCurrentActionName') $TextBlock3.Text = $TestInfo } $DispatcherTimerTS = New-Object -TypeName System.Windows.Threading.DispatcherTimer $DispatcherTimerTS.Interval = [TimeSpan]::FromMilliseconds(1000) $DispatcherTimerTS.Add_Tick($TimerCodeTS) #Timer for Upgrade % - Should be inactivate until activated in the Main Text Timer when it reaches the upgrade step. $TimerCodeUpgrade = { $CurlProcess = Get-Process -name Curl -ErrorAction SilentlyContinue if ($CurlProcess){ $TextBlock4.Visibility = 'Visible' $TextBlock4.Text = "Downloading Process: $(Get-NetworkStat) " } else { $TextBlock4.Visibility = 'Hidden' $TextBlock4.Text = "" } <# $TestInfoUpgrade = Get-ItemPropertyValue -Path "HKLM:\SYSTEM\Setup\MoSetup\Volatile" -Name "SetupProgress" if ($TestInfoUpgrade) {$TextBlock4.Text = "Windows Setup Engine: $($TestInfoUpgrade) %"} else {$TextBlock4.Text = "Windows Setup Engine: Initializing"} #> } $DispatcherTimerUpgrade = New-Object -TypeName System.Windows.Threading.DispatcherTimer $DispatcherTimerUpgrade.Interval = [TimeSpan]::FromSeconds(5) $DispatcherTimerUpgrade.Add_Tick($TimerCodeUpgrade) # Event: Window loaded $Window.Add_Loaded({ # Activate the window to bring it to the fore $This.Activate() # Fill the screen $Bounds = $screen.Bounds $Window.Left = $Bounds.Left $Window.Top = $Bounds.Top $Window.Height = $Bounds.Height $Window.Width = $Bounds.Width # Hide the taskbar [TaskBar]::Hide() # Hide the mouse cursor [System.Windows.Forms.Cursor]::Hide() # Begin animations $TextBlock.BeginAnimation([System.Windows.Controls.TextBlock]::OpacityProperty,$FadeinAnimation) $TextBlock2.BeginAnimation([System.Windows.Controls.TextBlock]::OpacityProperty,$FadeinAnimation) $TextBlock3.BeginAnimation([System.Windows.Controls.TextBlock]::OpacityProperty,$FadeinAnimation) $TextBlock4.BeginAnimation([System.Windows.Controls.TextBlock]::OpacityProperty,$FadeinAnimation) $ProgressRing.BeginAnimation([System.Windows.Controls.TextBlock]::OpacityProperty,$FadeinAnimation) $ColourBrighterAnimation.Add_Completed({ $Window.Background.BeginAnimation([System.Windows.Media.SolidColorBrush]::ColorProperty,$ColourDarkerAnimation) }) $Window.Background.BeginAnimation([System.Windows.Media.SolidColorBrush]::ColorProperty,$ColourBrighterAnimation) }) # Event: Window closing $Window.Add_Closing({ # Restore the taskbar [Taskbar]::Show() # Restore the mouse cursor [System.Windows.Forms.Cursor]::Show() $DispatcherTimer.Stop() $DispatcherTimerTS.Stop() }) # Event: Allows to close the window on right-click (uncomment for testing) <# $Window.Add_MouseRightButtonDown({ $This.Close() }) #> # Display the window $DispatcherTimer.Start() $DispatcherTimerTS.Start() $DispatcherTimerUpgrade.Start() $Window.ShowDialog() |