@@ -3,9 +3,8 @@ If (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]:
33 Try {
44 Start-Process PowerShell.exe - ArgumentList (" -NoProfile -ExecutionPolicy Bypass -File `" {0}`" " -f $PSCommandPath ) - Verb RunAs
55 Exit
6- }
7- Catch {
8- Write-Host " Failed to run as Administrator. Please rerun with elevated privileges."
6+ } Catch {
7+ Write-Host " Failed to run as Administrator. Please rerun with elevated privileges." - ForegroundColor Red
98 Exit
109 }
1110}
@@ -33,13 +32,62 @@ function SetStatusText {
3332
3433$script :currentScreenIndex = 1
3534
36- # URL to the XAML file on GitHub
37- $xamlUrl = " https://github.com/memstechtips/WIMUtil/raw/main/xaml/WIMUtilGUI.xaml"
35+ # Fix Internet Explorer Engine is Missing to Ensure GUI Launches
36+ Set-ItemProperty - Path " HKLM:\SOFTWARE\Microsoft\Internet Explorer\Main" - Name " DisableFirstRunCustomize" - Value 2 - Force
37+
38+ # Explicitly define the configuration URL for the branch to use (commenting out the one not to use depending on branch)
39+ $configUrl = " https://raw.githubusercontent.com/memstechtips/WIMUtil/main/config/wimutil-settings.json" # Main branch
40+ # $configUrl = "https://raw.githubusercontent.com/memstechtips/WIMUtil/dev/config/wimutil-settings.json" # Dev branch
41+
42+ Write-Host " Using Configuration URL: $configUrl " - ForegroundColor Cyan
43+
44+ # Determine branch from the configuration URL
45+ $currentBranch = " unknown" # Fallback value
46+ if ($configUrl -match " https://raw.githubusercontent.com/memstechtips/WIMUtil/([^/]+)/config/wimutil-settings.json" ) {
47+ $currentBranch = $matches [1 ]
48+ Write-Host " Branch detected from Configuration URL: $currentBranch " - ForegroundColor Green
49+ } else {
50+ Write-Host " Unable to detect branch from Configuration URL. Using fallback." - ForegroundColor Yellow
51+ }
3852
39- # Download and load the XAML content
53+ Write-Host " Using branch: $currentBranch " - ForegroundColor Cyan
54+
55+ # Load the configuration from the specified URL
4056try {
57+ $config = (Invoke-WebRequest - Uri $configUrl - ErrorAction Stop).Content | ConvertFrom-Json
58+ Write-Host " Configuration loaded successfully from $configUrl " - ForegroundColor Green
59+ } catch {
60+ Write-Host " Failed to load configuration from URL: $configUrl " - ForegroundColor Red
61+ exit 1
62+ }
63+
64+ # Fetch settings for the current branch
65+ $branchConfig = $config .$currentBranch
66+ if (-not $branchConfig ) {
67+ Write-Host " Branch $currentBranch not found in configuration file. Exiting script." - ForegroundColor Red
68+ exit 1
69+ }
70+
71+ Write-Host " Branch settings successfully loaded for: $currentBranch " - ForegroundColor Cyan
72+
73+ # Extract configuration settings
74+ $xamlUrl = $branchConfig.xamlUrl
75+ $oscdimgURL = $branchConfig.oscdimgURL
76+ $expectedHash = $branchConfig.expectedHash
77+
78+ # Validate that required keys are present in the configuration
79+ if (-not ($xamlUrl -and $oscdimgURL -and $expectedHash )) {
80+ Write-Host " Configuration file is missing required settings. Exiting script." - ForegroundColor Red
81+ exit 1
82+ }
83+
84+ # Load XAML GUI
85+ try {
86+ if (-not $xamlUrl ) {
87+ throw " XAML URL is not set in the configuration."
88+ }
4189 # Download XAML content as a string
42- $xamlContent = (Invoke-WebRequest - Uri $xamlUrl ).Content
90+ $xamlContent = (Invoke-WebRequest - Uri $xamlUrl - ErrorAction Stop ).Content
4391
4492 # Load the XAML using XamlReader.Load with a MemoryStream
4593 $encoding = [System.Text.Encoding ]::UTF8
@@ -52,13 +100,12 @@ try {
52100
53101 # Clean up stream
54102 $xamlStream.Close ()
55- }
56- catch {
103+ Write-Host " XAML GUI loaded successfully. " - ForegroundColor Green
104+ } catch {
57105 Write-Host " Error loading XAML from URL: $ ( $_.Exception.Message ) " - ForegroundColor Red
58- $readerOperationSuccessful = $false
106+ exit 1
59107}
60108
61-
62109# Define the drag behavior for the window
63110function Window_MouseLeftButtonDown {
64111 param (
@@ -80,7 +127,6 @@ function Update-ProgressIndicator {
80127 $ProgressStep4.Fill = if ($currentScreen -ge 4 ) { " #FFDE00" } else { " #FFEB99" }
81128}
82129
83-
84130# Check if XAML loaded successfully
85131if ($readerOperationSuccessful ) {
86132 # Define Controls consistently using $window
@@ -433,12 +479,6 @@ if ($readerOperationSuccessful) {
433479 [System.Windows.Forms.Application ]::DoEvents()
434480 }
435481
436-
437- # Define expected hash and signing date of oscdimg.exe file to determine if it's been tampered with
438- # Note: Different versions of oscdimg.exe will have different hashes and signing dates
439- $expectedHash = " CACD23ABCD1E1B791F6280D7D86270FF8D4144728FF611033BAF5599D883731B"
440- $expectedSignDate = [datetime ]" 2023-10-19T21:51:12"
441-
442482 # Function to get the SHA-256 hash of a file
443483 function Get-FileHashValue {
444484 param (
@@ -455,34 +495,6 @@ if ($readerOperationSuccessful) {
455495 }
456496 }
457497
458- # Function to get the signing date of a file
459- function Get-SignatureDate {
460- param (
461- [string ]$filePath
462- )
463-
464- if (Test-Path - Path $filePath ) {
465- try {
466- $signature = Get-AuthenticodeSignature - FilePath $filePath
467- if ($signature.Status -eq ' Valid' ) {
468- return $signature.SignerCertificate.NotBefore
469- }
470- else {
471- Write-Host " The file's digital signature is not valid."
472- return $null
473- }
474- }
475- catch {
476- Write-Host " Error retrieving the signature date: $_ "
477- return $null
478- }
479- }
480- else {
481- Write-Host " File not found at path: $filePath "
482- return $null
483- }
484- }
485-
486498 # Check if oscdimg exists on the system without checking hash or date
487499 function CheckOscdimg {
488500 $oscdimgPath = " C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Deployment Tools\amd64\Oscdimg\oscdimg.exe"
@@ -501,62 +513,50 @@ if ($readerOperationSuccessful) {
501513 [System.Windows.Forms.Application ]::DoEvents() # Refresh the UI
502514 }
503515
504- # Function to download and validate oscdimg
505- function DownloadOscdimg {
506- SetStatusText - message " Preparing to download oscdimg..." - color $Script :SuccessColor - textBlock ([ref ]$CreateISOStatusText )
507- [System.Windows.Forms.Application ]::DoEvents()
516+ # Function to download and validate oscdimg
517+ function DownloadOscdimg {
518+ SetStatusText - message " Preparing to download oscdimg..." - color $Script :SuccessColor - textBlock ([ref ]$CreateISOStatusText )
519+ [System.Windows.Forms.Application ]::DoEvents()
508520
509- $oscdimgURL = " https://github.com/memstechtips/WIMUtil/raw/main/assets/executables/oscdimg.exe"
510- $adkOscdimgPath = " C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Deployment Tools\amd64\Oscdimg"
511- $oscdimgFullPath = Join-Path - Path $adkOscdimgPath - ChildPath " oscdimg.exe"
521+ $adkOscdimgPath = " C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Deployment Tools\amd64\Oscdimg"
522+ $oscdimgFullPath = Join-Path - Path $adkOscdimgPath - ChildPath " oscdimg.exe"
512523
513- # Ensure the ADK directory exists
514- if (! (Test-Path - Path $adkOscdimgPath )) {
515- New-Item - ItemType Directory - Path $adkOscdimgPath - Force | Out-Null
516- SetStatusText - message " Created directory for oscdimg at: $adkOscdimgPath " - color $Script :SuccessColor - textBlock ([ref ]$CreateISOStatusText )
517- [System.Windows.Forms.Application ]::DoEvents()
518- }
524+ # Ensure the ADK directory exists
525+ if (! (Test-Path - Path $adkOscdimgPath )) {
526+ New-Item - ItemType Directory - Path $adkOscdimgPath - Force | Out-Null
527+ SetStatusText - message " Created directory for oscdimg at: $adkOscdimgPath " - color $Script :SuccessColor - textBlock ([ref ]$CreateISOStatusText )
528+ [System.Windows.Forms.Application ]::DoEvents()
529+ }
519530
520- # Download oscdimg to the ADK path
521- try {
522- SetStatusText - message " Downloading oscdimg to $adkOscdimgPath ... " - color $Script :SuccessColor - textBlock ([ref ]$CreateISOStatusText )
523- [System.Windows.Forms.Application ]::DoEvents()
531+ # Download oscdimg to the ADK path
532+ try {
533+ SetStatusText - message " Downloading oscdimg from: $oscdimgURL " - color $Script :SuccessColor - textBlock ([ref ]$CreateISOStatusText )
534+ [System.Windows.Forms.Application ]::DoEvents()
524535
525536 (New-Object System.Net.WebClient).DownloadFile($oscdimgURL , $oscdimgFullPath )
526- SetStatusText - message " oscdimg downloaded successfully." - color $Script :SuccessColor - textBlock ([ref ]$CreateISOStatusText )
527-
528- # Verify the file's hash
529- $actualHash = Get-FileHashValue - filePath $oscdimgFullPath
530- if ($actualHash -ne $expectedHash ) {
531- SetStatusText - message " Hash mismatch! oscdimg may not be from Microsoft." - color $Script :ErrorColor - textBlock ([ref ]$CreateISOStatusText )
532- Write-Host " Expected Hash: $expectedHash "
533- Write-Host " Actual Hash: $actualHash "
534- Remove-Item - Path $oscdimgFullPath - Force
535- return
536- }
537-
538- # Verify the file's signature date
539- $actualSignDate = Get-SignatureDate - filePath $oscdimgFullPath
540- if ($actualSignDate -ne $expectedSignDate ) {
541- SetStatusText - message " Signature date mismatch! oscdimg may not be from Microsoft." - color $Script :ErrorColor - textBlock ([ref ]$CreateISOStatusText )
542- Write-Host " Expected Sign Date: $expectedSignDate "
543- Write-Host " Actual Sign Date: $actualSignDate "
544- Remove-Item - Path $oscdimgFullPath - Force
545- return
546- }
547-
548- # File is valid, enable the Create ISO button
549- SetStatusText - message " oscdimg verified and ready for use." - color $Script :SuccessColor - textBlock ([ref ]$CreateISOStatusText )
550- $GetoscdimgButton.IsEnabled = $false
551- $CreateISOButton.IsEnabled = $true
552- }
553- catch {
554- SetStatusText - message " Failed to download oscdimg: $ ( $_.Exception.Message ) " - color $Script :ErrorColor - textBlock ([ref ]$CreateISOStatusText )
537+ Write-Host " oscdimg downloaded successfully from: $oscdimgURL "
538+
539+ # Verify the file's hash
540+ $actualHash = Get-FileHashValue - filePath $oscdimgFullPath
541+ if ($actualHash -ne $expectedHash ) {
542+ SetStatusText - message " Hash mismatch! oscdimg may not be from Microsoft." - color $Script :ErrorColor - textBlock ([ref ]$CreateISOStatusText )
543+ Write-Host " Expected Hash: $expectedHash "
544+ Write-Host " Actual Hash: $actualHash "
545+ Remove-Item - Path $oscdimgFullPath - Force
546+ return
555547 }
556548
557- [System.Windows.Forms.Application ]::DoEvents()
549+ # File is valid, enable the Create ISO button
550+ SetStatusText - message " oscdimg verified and ready for use." - color $Script :SuccessColor - textBlock ([ref ]$CreateISOStatusText )
551+ $GetoscdimgButton.IsEnabled = $false
552+ $CreateISOButton.IsEnabled = $true
553+ } catch {
554+ SetStatusText - message " Failed to download oscdimg: $ ( $_.Exception.Message ) " - color $Script :ErrorColor - textBlock ([ref ]$CreateISOStatusText )
558555 }
559556
557+ [System.Windows.Forms.Application ]::DoEvents()
558+ }
559+
560560 # Define the location selection function
561561 function SelectNewISOLocation {
562562 # Prompt the user for ISO save location
@@ -619,7 +619,6 @@ if ($readerOperationSuccessful) {
619619 $SelectISOLocationButton.Add_Click ({ SelectNewISOLocation })
620620 $CreateISOButton.Add_Click ({ CreateISO })
621621
622-
623622 # Event handler for the Next button
624623 # Next button to navigate to the next screen
625624 $NextButton.Add_Click ({
@@ -675,4 +674,4 @@ else {
675674 Write-Host " Failed to load the XAML file. Exiting script." - ForegroundColor Red
676675 Pause
677676 exit 1
678- }
677+ }
0 commit comments