From 919c4e73a2d4b2b8c896d3f028c4a6a6e4a994e6 Mon Sep 17 00:00:00 2001 From: Alan Mason <1923621+2Shirt@users.noreply.github.com> Date: Fri, 24 Nov 2017 21:01:27 -0800 Subject: [PATCH] 2016-04: Retroactive Updates * Finished code for 32-bit and 64-bit builds * Unified scripts for use under both builds --- {WK_32/Scripts => Scripts}/WK.ps1 | 6 +- {WK_32/Scripts => Scripts}/imaging.ps1 | 14 +- {WK_32/Scripts => Scripts}/init.ps1 | 0 {WK_32/Scripts => Scripts}/servers.ps1 | 0 System32/Winpeshl.ini | 2 +- System32/menu.cmd | 2 +- {WK_32 => WK/amd64}/CPU-Z/cpuz.ini | 0 {WK_32 => WK/amd64}/ConEmu/ConEmu.xml | 0 {WK_32 => WK/amd64}/Explorer++/config.xml | 0 {WK_32 => WK/amd64}/HWMonitor/hwmonitorw.ini | 0 {WK_32 => WK/amd64}/Notepad2/Notepad2.ini | 0 {WK_64 => WK/x86}/CPU-Z/cpuz.ini | 0 {WK_64 => WK/x86}/ConEmu/ConEmu.xml | 0 {WK_64 => WK/x86}/Explorer++/config.xml | 0 {WK_64 => WK/x86}/HWMonitor/hwmonitorw.ini | 0 {WK_64 => WK/x86}/Notepad2/Notepad2.ini | 0 WK_64/Scripts/WK.ps1 | 116 ----- WK_64/Scripts/imaging.ps1 | 467 ------------------- WK_64/Scripts/init.ps1 | 158 ------- WK_64/Scripts/servers.ps1 | 85 ---- make-cd.cmd | 37 -- make.cmd | 246 ++++++---- 22 files changed, 176 insertions(+), 957 deletions(-) rename {WK_32/Scripts => Scripts}/WK.ps1 (91%) rename {WK_32/Scripts => Scripts}/imaging.ps1 (95%) rename {WK_32/Scripts => Scripts}/init.ps1 (100%) rename {WK_32/Scripts => Scripts}/servers.ps1 (100%) rename {WK_32 => WK/amd64}/CPU-Z/cpuz.ini (100%) rename {WK_32 => WK/amd64}/ConEmu/ConEmu.xml (100%) rename {WK_32 => WK/amd64}/Explorer++/config.xml (100%) rename {WK_32 => WK/amd64}/HWMonitor/hwmonitorw.ini (100%) rename {WK_32 => WK/amd64}/Notepad2/Notepad2.ini (100%) rename {WK_64 => WK/x86}/CPU-Z/cpuz.ini (100%) rename {WK_64 => WK/x86}/ConEmu/ConEmu.xml (100%) rename {WK_64 => WK/x86}/Explorer++/config.xml (100%) rename {WK_64 => WK/x86}/HWMonitor/hwmonitorw.ini (100%) rename {WK_64 => WK/x86}/Notepad2/Notepad2.ini (100%) delete mode 100644 WK_64/Scripts/WK.ps1 delete mode 100644 WK_64/Scripts/imaging.ps1 delete mode 100644 WK_64/Scripts/init.ps1 delete mode 100644 WK_64/Scripts/servers.ps1 delete mode 100644 make-cd.cmd diff --git a/WK_32/Scripts/WK.ps1 b/Scripts/WK.ps1 similarity index 91% rename from WK_32/Scripts/WK.ps1 rename to Scripts/WK.ps1 index bf346b17..d18fc94f 100644 --- a/WK_32/Scripts/WK.ps1 +++ b/Scripts/WK.ps1 @@ -27,16 +27,16 @@ function menu-tools { # Avail tools $tools = @( @{Name="Blue Screen View"; Folder="BlueScreenView"; File="BlueScreenView.exe"}, + @{Name="CPU-Z"; Folder="CPU-Z"; File="cpuz.exe"}, @{Name="Explorer++"; Folder="Explorer++"; File="Explorer++.exe"}, @{Name="Fast Copy"; Folder="FastCopy"; File="FastCopy.exe"; Args=@('/cmd=noexist_only', '/utf8', '/skip_empty_dir', '/linkdest', '/exclude="desktop.ini;Thumbs.db"')}, @{Name="HW Monitor"; Folder="HWMonitor"; File="HWMonitor.exe"}, @{Name="NT Password Editor"; Folder="NT Password Editor"; File="ntpwedit.exe"}, @{Name="Notepad2"; Folder="Notepad2"; File="Notepad2-Mod.exe"}, + @{Name="PhotoRec"; Folder="TestDisk"; File="photorec_win.exe"}, @{Name="Prime95"; Folder="Prime95"; File="prime95.exe"}, @{Name="ProduKey"; Folder="ProduKey"; File="ProduKey.exe"}, - @{Name="PhotoRec (GUI)"; Folder="TestDisk"; File="qphotorec_win.exe"}, - @{Name="PhotoRec (CLI)"; Folder="TestDisk"; File="photorec_win.exe"}, - @{Name="TestDisk (CLI)"; Folder="TestDisk"; File="testdisk_win.exe"} + @{Name="TestDisk"; Folder="TestDisk"; File="testdisk_win.exe"} ) # Build menu diff --git a/WK_32/Scripts/imaging.ps1 b/Scripts/imaging.ps1 similarity index 95% rename from WK_32/Scripts/imaging.ps1 rename to Scripts/imaging.ps1 index 38b48b4c..a8a4e540 100644 --- a/WK_32/Scripts/imaging.ps1 +++ b/Scripts/imaging.ps1 @@ -19,14 +19,14 @@ function apply-image { $volumes = @(Get-Volume | Where-Object {$_.Size -ne 0 -and $_.DriveLetter -imatch '^[C-Z]$'}) foreach ($v in $volumes) { $letter = $v.DriveLetter + ":" - if (Test-Path "$letter\sources\$image.wim") { - $path = "$letter\sources\$image.wim" - } elseif (Test-Path "$letter\sources\$image.esd") { - $path = "$letter\sources\$image.esd" - } elseif (Test-Path "$letter\sources\$image.swm") { - $path = "$letter\sources\$image.swm" + if (Test-Path "$letter\images\$image.wim") { + $path = "$letter\images\$image.wim" + } elseif (Test-Path "$letter\images\$image.esd") { + $path = "$letter\images\$image.esd" + } elseif (Test-Path "$letter\images\$image.swm") { + $path = "$letter\images\$image.swm" $split_image = $true - $split_image_pattern = "$letter\sources\$image*.swm" + $split_image_pattern = "$letter\images\$image*.swm" } } diff --git a/WK_32/Scripts/init.ps1 b/Scripts/init.ps1 similarity index 100% rename from WK_32/Scripts/init.ps1 rename to Scripts/init.ps1 diff --git a/WK_32/Scripts/servers.ps1 b/Scripts/servers.ps1 similarity index 100% rename from WK_32/Scripts/servers.ps1 rename to Scripts/servers.ps1 diff --git a/System32/Winpeshl.ini b/System32/Winpeshl.ini index 313d0a7b..ed840fb7 100644 --- a/System32/Winpeshl.ini +++ b/System32/Winpeshl.ini @@ -2,4 +2,4 @@ [LaunchApps] wpeinit wpeutil updatebootinfo -"%SystemDrive%\WK\ConEmu\ConEmu64.exe", /cmd PowerShell -ExecutionPolicy Bypass "%SystemDrive%\WK\Scripts\WK.ps1" -new_console:n \ No newline at end of file +"%SystemDrive%\WK\ConEmu\ConEmu.exe", /cmd PowerShell -ExecutionPolicy Bypass "%SystemDrive%\WK\Scripts\WK.ps1" -new_console:n diff --git a/System32/menu.cmd b/System32/menu.cmd index eb9c80be..c433ff39 100644 --- a/System32/menu.cmd +++ b/System32/menu.cmd @@ -12,7 +12,7 @@ for %%f in (%*) do ( ) :LaunchMenu -"%SystemDrive%\WK\ConEmu\ConEmu64.exe" /cmd PowerShell -ExecutionPolicy Bypass "%SystemDrive%\WK\Scripts\WK.ps1" -new_console:n +"%SystemDrive%\WK\ConEmu\ConEmu.exe" /cmd PowerShell -ExecutionPolicy Bypass "%SystemDrive%\WK\Scripts\WK.ps1" -new_console:n goto Done :Abort diff --git a/WK_32/CPU-Z/cpuz.ini b/WK/amd64/CPU-Z/cpuz.ini similarity index 100% rename from WK_32/CPU-Z/cpuz.ini rename to WK/amd64/CPU-Z/cpuz.ini diff --git a/WK_32/ConEmu/ConEmu.xml b/WK/amd64/ConEmu/ConEmu.xml similarity index 100% rename from WK_32/ConEmu/ConEmu.xml rename to WK/amd64/ConEmu/ConEmu.xml diff --git a/WK_32/Explorer++/config.xml b/WK/amd64/Explorer++/config.xml similarity index 100% rename from WK_32/Explorer++/config.xml rename to WK/amd64/Explorer++/config.xml diff --git a/WK_32/HWMonitor/hwmonitorw.ini b/WK/amd64/HWMonitor/hwmonitorw.ini similarity index 100% rename from WK_32/HWMonitor/hwmonitorw.ini rename to WK/amd64/HWMonitor/hwmonitorw.ini diff --git a/WK_32/Notepad2/Notepad2.ini b/WK/amd64/Notepad2/Notepad2.ini similarity index 100% rename from WK_32/Notepad2/Notepad2.ini rename to WK/amd64/Notepad2/Notepad2.ini diff --git a/WK_64/CPU-Z/cpuz.ini b/WK/x86/CPU-Z/cpuz.ini similarity index 100% rename from WK_64/CPU-Z/cpuz.ini rename to WK/x86/CPU-Z/cpuz.ini diff --git a/WK_64/ConEmu/ConEmu.xml b/WK/x86/ConEmu/ConEmu.xml similarity index 100% rename from WK_64/ConEmu/ConEmu.xml rename to WK/x86/ConEmu/ConEmu.xml diff --git a/WK_64/Explorer++/config.xml b/WK/x86/Explorer++/config.xml similarity index 100% rename from WK_64/Explorer++/config.xml rename to WK/x86/Explorer++/config.xml diff --git a/WK_64/HWMonitor/hwmonitorw.ini b/WK/x86/HWMonitor/hwmonitorw.ini similarity index 100% rename from WK_64/HWMonitor/hwmonitorw.ini rename to WK/x86/HWMonitor/hwmonitorw.ini diff --git a/WK_64/Notepad2/Notepad2.ini b/WK/x86/Notepad2/Notepad2.ini similarity index 100% rename from WK_64/Notepad2/Notepad2.ini rename to WK/x86/Notepad2/Notepad2.ini diff --git a/WK_64/Scripts/WK.ps1 b/WK_64/Scripts/WK.ps1 deleted file mode 100644 index bf346b17..00000000 --- a/WK_64/Scripts/WK.ps1 +++ /dev/null @@ -1,116 +0,0 @@ -# WK-Checklist - -## Init ## -$wd = $(Split-Path $MyInvocation.MyCommand.Path) -pushd "$wd" -. .\init.ps1 -. .\servers.ps1 -. .\imaging.ps1 -clear -$host.UI.RawUI.WindowTitle = "WK PE Tool" -$logpath = "$WKPath\Info\$date" -md "$logpath" 2>&1 | Out-Null -$log = "$logpath\winpe.log" - -# Functions -function wk-exit { - param([string]$action) - switch ($action) { - 'Q' {PowerShell -ExecutionPolicy Bypass; break} - 'R' {wpeutil reboot; break} - 'S' {wpeutil shutdown; break} - default {throw} - } - exit 0 -} -function menu-tools { - # Avail tools - $tools = @( - @{Name="Blue Screen View"; Folder="BlueScreenView"; File="BlueScreenView.exe"}, - @{Name="Explorer++"; Folder="Explorer++"; File="Explorer++.exe"}, - @{Name="Fast Copy"; Folder="FastCopy"; File="FastCopy.exe"; Args=@('/cmd=noexist_only', '/utf8', '/skip_empty_dir', '/linkdest', '/exclude="desktop.ini;Thumbs.db"')}, - @{Name="HW Monitor"; Folder="HWMonitor"; File="HWMonitor.exe"}, - @{Name="NT Password Editor"; Folder="NT Password Editor"; File="ntpwedit.exe"}, - @{Name="Notepad2"; Folder="Notepad2"; File="Notepad2-Mod.exe"}, - @{Name="Prime95"; Folder="Prime95"; File="prime95.exe"}, - @{Name="ProduKey"; Folder="ProduKey"; File="ProduKey.exe"}, - @{Name="PhotoRec (GUI)"; Folder="TestDisk"; File="qphotorec_win.exe"}, - @{Name="PhotoRec (CLI)"; Folder="TestDisk"; File="photorec_win.exe"}, - @{Name="TestDisk (CLI)"; Folder="TestDisk"; File="testdisk_win.exe"} - ) - - # Build menu - $selection = $null - $actions = @(@{Name="Main Menu"; Letter="M"}) - - # Run Loop - $_done = $false - do { - $selection = (menu-select "Tools Menu" $tools $actions) - - if ($selection -imatch '^M$') { - # User selected to return to the menu - return $false - } elseif ($selection -inotmatch '^\d+$') { - # This shouldn't happen? - throw - } else { - $selection -= 1 - $path = "{0}\{1}" -f $WKPath, $tools[$selection].Folder - if ($tools[$selection].ContainsKey("Args")) { - Start-Process $tools[$selection].File -ArgumentList $tools[$selection].Args -WorkingDirectory $path - } else { - Start-Process $tools[$selection].File -WorkingDirectory $path - } - } - } until ($_done) -} -function menu-main { - # Build menu - $selection = $null - $menus = @( - @{Name="Drive Imaging"; Menu="menu-imaging"} - @{Name="Windows Setup"; Menu="menu-setup"} - @{Name="Misc Tools"; Menu="menu-tools"} - ) - $actions = @( - @{Name="Command Prompt"; Letter="C"} - @{Name="PowerShell"; Letter="P"} - @{Name="Reboot"; Letter="R"} - @{Name="Shutdown"; Letter="S"} - ) - - # Show Menu - $selection = (menu-select "Main Menu" $menus $actions -SecretExit $true) - - if ($selection -imatch '^C$') { - Start-Process "$windir\System32\cmd.exe" -argumentlist @("-new_console:n") -WorkingDirectory "$WKPath" - return - } elseif ($selection -imatch '^P$') { - Start-Process "$windir\System32\WindowsPowerShell\v1.0\powershell.exe" -argumentlist @("-ExecutionPolicy", "Bypass", "-new_console:n") -WorkingDirectory "$WKPath" - return - } elseif ($selection -imatch '^[QRS]$') { - wk-exit $selection - return - } elseif ($selection -inotmatch '^\d+$') { - # This shouldn't happen? - throw - } else { - # Launch sub-menu - $selection -= 1 - & $menus[$selection].Menu - } -} - -# Mount all partitions -foreach ($_d in @(Get-Disk)) { - foreach ($_p in @(Get-Partition -DiskNumber $_d.DiskNumber)) { - # Assign letter - Add-PartitionAccessPath -DiskNumber $_d.DiskNumber -PartitionNumber $_p.PartitionNumber -AssignDriveLetter 2>&1 | Out-Null - } -} - -# Main Loop -do { - menu-main -} while ($true) diff --git a/WK_64/Scripts/imaging.ps1 b/WK_64/Scripts/imaging.ps1 deleted file mode 100644 index 38b48b4c..00000000 --- a/WK_64/Scripts/imaging.ps1 +++ /dev/null @@ -1,467 +0,0 @@ -# WK imaging functions - -## Init ## -$wd = $(Split-Path $MyInvocation.MyCommand.Path) -pushd "$wd" -. .\init.ps1 - -# Functions -function apply-image { - # Apply a Windows image to W:\ - Param([string]$image, [string]$name) - $path = "" - $split_image = $false - $split_image_pattern = "" - - # Check for source image - ## This checks all drive letters for the source image. - ## It starts with local sources and then tries the server(s) (usually Y: and Z:) - $volumes = @(Get-Volume | Where-Object {$_.Size -ne 0 -and $_.DriveLetter -imatch '^[C-Z]$'}) - foreach ($v in $volumes) { - $letter = $v.DriveLetter + ":" - if (Test-Path "$letter\sources\$image.wim") { - $path = "$letter\sources\$image.wim" - } elseif (Test-Path "$letter\sources\$image.esd") { - $path = "$letter\sources\$image.esd" - } elseif (Test-Path "$letter\sources\$image.swm") { - $path = "$letter\sources\$image.swm" - $split_image = $true - $split_image_pattern = "$letter\sources\$image*.swm" - } - } - - # Check for FQDN remote source (if necessary) - if ($path -imatch '^$') { - # Temporarily set path to network source - $path = "\\$source_server\Windows\$image" - wk-warn "Searching for network source" - if (Test-Path "$path.wim") { - $path = "$path.wim" - } elseif (Test-Path "$path.esd") { - $path = "$path.esd" - } elseif (Test-Path "$path.swm") { - $path = "$path.swm" - $split_image = $true - $split_image_pattern = "$path*.swm" - } else { - # Revert to empty path if nothing found. - $path = "" - } - } - - # Expand Image - if ($path -imatch 'Win\d+\.(esd|wim)$') { - wk-write " Applying image..." - Expand-WindowsImage -ImagePath "$path" -Name "$name" -ApplyPath 'W:\' | out-null - } elseif ($path -imatch 'Win\d+\.swm$') { - wk-write " Applying split-image..." - Expand-WindowsImage -ImagePath "$path" -Name "$name" -ApplyPath 'W:\' -SplitImageFilePattern "$split_image_pattern" | out-null - } else { - wk-error "Image not found." - throw - } -} -function format-gpt { - Param($dest_disk) - wk-write "Drive will use a GPT (UEFI) layout." - - # Double-check we have the right drive - ## I don't trust the order will be the same for diskpart & PS Storage Cmdlets - $_sel_uid = $dest_disk.Guid - if ($dest_disk.PartitionStyle -imatch "MBR") { - # MBR disks don't have GUIDs and use the signature in hex instead - $_sel_uid = "{0:x}" -f $dest_disk.Signature - } - $diskpart_script = "select disk {0}`r`n" -f $dest_disk.DiskNumber - $diskpart_script += "uniqueid disk" - Out-File -encoding 'UTF8' -filepath "$wd\diskpart.script" -inputobject $diskpart_script - Start-Process "diskpart" -argumentlist @("/s", "$wd\diskpart.script") -wait -nonewwindow -PassThru -RedirectStandardOutput "$wd\drive_uid" | Out-Null - if (!(Get-Content "$wd\drive_uid" | Where-Object {$_ -imatch $_sel_uid})) { - # GUIDs do not match - wk-error "Diskpart failed to select the same disk for formatting, aborting setup." - wk-warn "This system requires manual formatting & setup" - wk-write "" - throw "Failed to format disk" - } else { - wk-write ("Selecting Disk {0} ({1})" -f $dest_disk.DiskNumber, $_sel_uid) - } - - # Generate Diskpart script and execute - ## NOTE 1: PS Storage Cmdlets can't be used; See Keith Garner's response here: - ## https://social.technet.microsoft.com/Forums/en-US/9d78da31-557f-4408-89e0-a1603f7ebe0d - ## - ## NOTE 2: This overwrites existing diskpart.script file without confirmation. - $diskpart_script = "select disk {0}`r`n" -f $dest_disk.DiskNumber - $diskpart_script += "clean`r`n" - $diskpart_script += "convert gpt`r`n" - - # 1. Windows RE tools partition (Windows 8+) - if ($dest_windows_version.Name -imatch '^Windows (8|10)') { - $diskpart_script += "create partition primary size=300`r`n" - $diskpart_script += "format quick fs=ntfs label='Windows RE tools'`r`n" - $diskpart_script += "assign letter='T'`r`n" - $diskpart_script += "set id='de94bba4-06d1-4d40-a16a-bfd50179d6ac'`r`n" - $diskpart_script += "gpt attributes=0x8000000000000001`r`n" - } - - # 2. System partition - $diskpart_script += "create partition efi size=260`r`n" - ## NOTE: Allows for Advanced Format 4Kn drives - $diskpart_script += "format quick fs=fat32 label='System'`r`n" - $diskpart_script += "assign letter='S'`r`n" - - # 3. Microsoft Reserved (MSR) partition - $diskpart_script += "create partition msr size=128`r`n" - - # 4. Windows partition - $diskpart_script += "create partition primary`r`n" - $diskpart_script += "format quick fs=ntfs label='Windows'`r`n" - $diskpart_script += "assign letter='W'`r`n" - - # Run script - Out-File -encoding 'UTF8' -filepath "$wd\diskpart.script" -inputobject $diskpart_script - Start-Process "diskpart" -argumentlist @("/s", "$wd\diskpart.script") -wait -nonewwindow | out-null -} -function format-mbr { - Param($dest_disk) - wk-write "Drive will use a MBR (legacy) layout." - - if ($dest_disk.PartitionStyle -inotmatch '^RAW$') { - # Only clean if necessary - clear-Disk $dest_disk.DiskNumber -RemoveData -RemoveOEM -Confirm:$false | out-null - } - Initialize-Disk $dest_disk.DiskNumber -PartitionStyle 'MBR' | out-null - New-Partition -DiskNumber $dest_disk.DiskNumber -Size 100Mb -DriveLetter 'S' -IsActive:$true | out-null - New-Partition -DiskNumber $dest_disk.DiskNumber -UseMaximumSize -DriveLetter 'W' -IsActive:$false | out-null - Format-Volume -DriveLetter 'S' -FileSystem 'NTFS' -NewFileSystemLabel 'System Reserved' | out-null - Format-Volume -DriveLetter 'W' -FileSystem 'NTFS' -NewFileSystemLabel 'Windows' | out-null -} -function select-disk { - param([string]$title, [bool]$skip_usb=$false) - $_skipped_parts = 0 - - # Get Disk(s) - if ($skip_usb) { - $disks = @(Get-Disk | Where-Object {$_.Size -ne 0 -and $_.BusType -inotmatch 'USB'} | Sort-Object -Property "Number") - } else { - $disks = @(Get-Disk | Where-Object {$_.Size -ne 0} | Sort-Object -Property "Number") - } - - # Check if any drives were detected - if ($disks.count -eq 0) { - wk-error "No suitable drives were detected." - return $false - } - - # Get selection - $selection = $null - $main_set = @() - if ($disks.count -eq 1) { - # Only one disk is available - $selection = $disks[0] - } else { - # Multiple options. Build and use menu - foreach ($_ in $disks) { - $_entry = "{0}`t[{1}] ({2}) {3}" -f (human-size $_.Size 0), $_.PartitionStyle, $_.BusType, $_.FriendlyName - $main_set += @{Name=$_entry} - } - $actions = @(@{Name="Main Menu"; Letter="M"}) - $selection = (menu-select $title $main_set $actions) - } - - if ($selection -imatch '^\d+$') { - $selection -= 1 - return $disks[$selection] - } else { - return $selection - } -} -function menu-imaging { - wk-write "Drive Imaging" - wk-write "" - - # Pre-emptively mount Server(s) - ## Helps ensure a successfull backup and/or setup - mount-servers - - ## WARNING - wk-warn "WARNING: This section is experimental" - pause - ## WARNING - - # Service Order - $menu_service_order += "Please enter the service order`r`n" - do { - clear - $service_order = read-host -prompt $menu_service_order - } until ($service_order -imatch '^\d[\w\-]+$') - - # Select Disk - $disk = (select-disk "For which drive are we creating backup image(s)?") - - if (!($disk)) { - # No drives detected or user aborted - wk-warn "Drive Imaging aborted." - wk-write "" - pause "Press Enter to return to main menu... " -warning=$true - return $false - } elseif ($disk -imatch '^M$') { - # User selected to return to the menu - return $false - } elseif ($disk.DiskNumber -imatch '^\d+$') { - # Valid disk selected - clear - wk-write ("Disk:`t{0}`t[{1}] ({2}) {3}" -f (human-size $disk.Size 0), $disk.PartitionStyle, $disk.BusType, $disk.FriendlyName) - wk-write "Partition(s):" - - # Print partition info - $partitions = Get-Partition -DiskNumber $disk.DiskNumber - $_skipped_parts = 0 - foreach ($_p in $partitions) { - # Assign letter - Add-PartitionAccessPath -DiskNumber $disk.DiskNumber -PartitionNumber $_p.PartitionNumber -AssignDriveLetter 2>&1 | Out-Null - - # Update partition info - $_p = Get-Partition -DiskNumber $disk.DiskNumber -PartitionNumber $_p.PartitionNumber - $_v = Get-Volume -Partition $_p - - # Set size label - $_size = (human-size $_p.size 0) - $_used = "" - if ($_v) { - $_used = "({0} used)" -f (human-size ($_v.Size - $_v.SizeRemaining) 0) - } - - # Print partition info - if ($_p.AccessPaths) { - # Has drive letter - $_path = $_p.AccessPaths | Where-Object {$_ -imatch '^\w:\\$'} - $_label = " {0}" -f $_p.Type - if ($_v -and $_v.FileSystemLabel -ne "") { - $_label = '"{0}"' -f $_v.FileSystemLabel - } - $_msg = " {0:N0}:`t{1} ({2,6}) {3} {4}" -f $_p.PartitionNumber, $_path, $_size, $_label, $_used - wk-write "$_msg" - } else { - # No drive letter - $_msg = " *{0:N0}:`t ({1}) {2}" -f $_p.PartitionNumber, $_size, $_p.Type - wk-error "$_msg" - $_skipped_parts += 1 - } - } - if ($_skipped_parts -gt 0) { - wk-warn " *`tUnable to backup these partition(s)" - } - wk-write "" - if (!(ask " Backup these partition(s)?")) { - wk-warn "Drive Imaging aborted." - wk-write "" - pause "Press Enter to return to main menu... " -warning=$true - return $false - } - } - wk-write "" - - # Select Server - $server = (select-server) - if (!($server)) { - # No servers detected - wk-warn "Drive Imaging aborted." - wk-write "" - pause "Press Enter to return to main menu... " -warning=$true - return $false - } elseif ($server -imatch '^M$') { - # User selected to return to the menu - return - } - wk-write "" - wk-write ("Saving partition backups to: {0}" -f $server.Description) - wk-write "" - - # Backup partitions - $partitions = Get-Partition -DiskNumber $disk.DiskNumber - foreach ($_p in $partitions) { - $_v = Get-Volume -Partition $_p - - $_name = "{0}" -f $_p.PartitionNumber - if ($_v -and $_v.FileSystemLabel -ne "") { - $_name += "_{0}" -f $_v.FileSystemLabel - } else { - $_name += "_{0}" -f $_p.Type - } - # Sanitize the name - $_name = $_name -replace '\s', '_' - - $_imagepath = "{0}{1}" -f $server.Root, $service_order - $_imagefile = "{0}{1}\{2}.wim" -f $server.Root, $service_order, $_name - - if ($_p.AccessPaths -ne $null) { - # Avoid unwanted clobbering - if (Test-Path "$_imagefile") { - if (!(ask ("Overwrite backup image: {0}" -f $_imagefile))) { - wk-warn "Drive Imaging aborted." - wk-write "" - pause "Press Enter to return to main menu... " -warning=$true - return $false - } - } - $_capturedir = $_p.AccessPaths | Where-Object {$_ -imatch '^\w:\\$'} - - # Take image - wk-write (" Imaging partition {0} --> `"{1}`"" -f $_p.PartitionNumber, $_imagefile) - if (!(Test-Path "$_imagepath")) { - mkdir "$_imagepath" | out-null - } - $_dism_args = @( - "/Capture-Image", - "/ImageFile:$_imagefile", - "/CaptureDir:$_capturedir", - "/Name:$_name", - "/Compress:fast", - "/Quiet") - Start-Process "$windir\System32\Dism.exe" -ArgumentList $_dism_args -NoNewWindow -Wait | out-null - - ## The following command fails to capture OS partitions consitantly. Until this is fixed I will use DISM directly (as above). - #New-WindowsImage -ImagePath "$_imagefile" -CapturePath "$_capturedir" -Name "$_name" -CompressionType "fast" | out-null - - # Verify image - ## Code borrowed from: https://stackoverflow/a/10262275 - $pinfo = New-Object System.Diagnostics.ProcessStartInfo - $pinfo.FileName = "$WKPath\7-Zip\7z.exe" - $pinfo.RedirectStandardError = $true - $pinfo.RedirectStandardOutput = $true - $pinfo.UseShellExecute = $false - $pinfo.Arguments = 't "{0}"' -f $_imagefile - $p = New-Object System.Diagnostics.Process - $p.StartInfo = $pinfo - $p.Start() | Out-Null - write-host " Verifying . . . " -NoNewline - $p.WaitForExit() - if ($p.ExitCode -eq 0) { - write-host "Complete." -foreground "green" - } else { - write-host "Failed." -foreground "red" - } - } - } - pause "Press Enter to return to main menu... " -} -function menu-setup { - # Pre-emptively mount Server(s) - ## Helps ensure a successfull backup and/or setup - mount-servers - - # Select Disk - $dest_disk = (select-disk "To which drive are we installing Windows?" -skip_usb=$true) - - if (!($dest_disk)) { - # No drives detected or user aborted - wk-warn "Windows Setup aborted." - wk-write "" - pause "Press Enter to return to main menu... " -warning=$true - return $false - } elseif ($dest_disk -imatch '^M$') { - # User selected to return to the menu - return $false - } elseif ($dest_disk.DiskNumber -inotmatch '^\d+$') { - # This shouldn't happen? - throw - } else { - wk-warn "All data will be deleted from the following drive:" - wk-warn ("`t{0}`t({1}) {2}`r`n" -f (human-size $dest_disk.Size 0), $dest_disk.PartitionStyle, $dest_disk.FriendlyName) - if (!(ask "Proceed and install Windows?")) { - wk-warn "Windows Setup aborted." - wk-write "" - pause "Press Enter to return to main menu... " -warning=$true - return $false - } - } - - # Set available Windows versions - $windows_versions = @( - @{Name="Windows 7 Home Basic"; ImageFile="Win7"; ImageName="Windows 7 HOMEBASIC"} - @{Name="Windows 7 Home Premium"; ImageFile="Win7"; ImageName="Windows 7 HOMEPREMIUM"} - @{Name="Windows 7 Professional"; ImageFile="Win7"; ImageName="Windows 7 PROFESSIONAL"} - @{Name="Windows 7 Ultimate"; ImageFile="Win7"; ImageName="Windows 7 ULTIMATE"} - - @{Name="Windows 8.1"; ImageFile="Win8"; ImageName="Windows 8.1"; CRLF=$true} - @{Name="Windows 8.1 Pro"; ImageFile="Win8"; ImageName="Windows 8.1 Pro"} - - # The ISOs from the MediaCreationTool are apparently Technical Previews - @{Name="Windows 10 Home"; ImageFile="Win10"; ImageName="Windows 10 Technical Preview"; CRLF=$true} - @{Name="Windows 10 Pro"; ImageFile="Win10"; ImageName="Windows 10 Pro Technical Preview"} - ) - - # Build menu and get selection - $dest_windows_version = $null - $selection = $null - $actions = @(@{Name="Main Menu"; Letter="M"}) - $selection = (menu-select "Which version of Windows are we installing?" $windows_versions $actions) - - if ($selection -imatch '^M$') { - # User selected to return to the menu - return $false - } elseif ($selection -inotmatch '^\d+$') { - # This shouldn't happen? - throw - } else { - $selection -= 1 - $dest_windows_version = $windows_versions[$selection] - } - - # Double check before deleting data - wk-warn "SAFTEY CHECK:" - wk-write (" Installing:`t{0}" -f $dest_windows_version.Name) - wk-error (" And ERASING:`tDisk: {0}`t({1}) {2}`r`n" -f (human-size $dest_disk.Size 0), $dest_disk.PartitionStyle, $dest_disk.FriendlyName) - if (!(ask "Is this correct?")) { - wk-warn "Windows Setup aborted." - wk-write "" - pause "Press Enter to return to main menu... " -warning=$true - return $false - } - - ## WARNING - wk-warn "WARNING: This section is experimental" - ## WARNING - - ## Here be dragons - try { - # Select UEFI or BIOS partition layout - if ($UEFI) { - # System booted via UEFI so assume new layout should be GPT - if (ask "Setup drive using GPT (UEFI) layout?") { - format-gpt $dest_disk - } else { - format-mbr $dest_disk - } - } else{ - if (ask "Setup drive using MBR (legacy) layout?") { - format-mbr $dest_disk - } else { - format-gpt $dest_disk - } - } - - # Apply image - apply-image $dest_windows_version.ImageFile $dest_windows_version.ImageName - - # Create boot files (copies files for both Legacy and UEFI) - wk-write " Copying boot files..." - bcdboot W:\Windows /s S: /f ALL 2>&1 | out-null - if ($dest_windows_version.Name -imatch '^Windows (8|10)') { - W:\Windows\System32\reagentc /setreimage /path T:\Recovery\WindowsRE /target W:\Windows 2>&1 | out-null - } - - # Done - wk-write "Windows Setup complete." - wk-write "" - pause "Press Enter to return to main menu... " - } catch { - # Error(s) - wk-error "$Error" - wk-error "Windows Setup aborted." - wk-write "" - pause "Press Enter to return to main menu... " -warning=$true - return $false - } -} diff --git a/WK_64/Scripts/init.ps1 b/WK_64/Scripts/init.ps1 deleted file mode 100644 index b198fdd8..00000000 --- a/WK_64/Scripts/init.ps1 +++ /dev/null @@ -1,158 +0,0 @@ -# WK-Init -# -# Some common settings and functions - -$host.UI.RawUI.BackgroundColor = "black" -$host.UI.RawUI.ForegroundColor = "cyan" -#$appdata = (gci env:appdata).value -#$localappdata = (gci env:localappdata).value -#$username = (gci env:username).value -#$userprofile = (gci env:userprofile).value -$systemdrive = (gci env:systemdrive).value -$windir = (gci env:windir).value -#$programfiles = (gci env:programfiles).value -#$programfiles86 = $programfiles -#if (test-path env:"programfiles(x86)") { -# $programfiles86 = (gci env:"programfiles(x86)").value -#} -$WKPath = "$systemdrive\WK" -$date = get-date -uformat "%Y-%m-%d" -#$logpath = "$WKPath\Info\$date" - -# Check if booted via UEFI -$UEFI = $false -if ((Get-ItemProperty -path "HKLM:\System\CurrentControlSet\Control").PEFirmwareType -eq 2) { - $UEFI = $true -} - -function ask { - param([string]$text = "Kotaero", [string]$log = "WK.log") - $answered = $false - $text += " [Y/N]" - while (!$answered) { - $answer = read-host $text - if ($answer -imatch '^(y|yes)$') { - $answer = $true - $answered = $true - } elseif ($answer -imatch '^(n|no)$') { - $answer = $false - $answered = $true - } - } - $text += ": $answer" - out-file -filepath $log -inputobject $text -append - return $answer -} -function wk-error { - param([string]$text = "ERROR", [string]$log = "WK.log") - write-host ($text) -foreground "red" - out-file -filepath $log -inputobject $text -append -} -function wk-warn { - param([string]$text = "WARNING", [string]$log = "WK.log") - write-host ($text) -foreground "yellow" - out-file -filepath $log -inputobject $text -append -} -function wk-write { - param([string]$text = "", [string]$log = "WK.log") - write-host ($text) - out-file -filepath $log -inputobject $text -append -} -function human-size { - param($bytes, [int]$decimals = 2) - if ($bytes -gt 1Tb) { - $size = "{0:N$decimals} Tb" -f ($bytes / 1Tb) - } elseif ($bytes -gt 1Gb) { - $size = "{0:N$decimals} Gb" -f ($bytes / 1Gb) - } elseif ($bytes -gt 1Mb) { - $size = "{0:N$decimals} Mb" -f ($bytes / 1Mb) - } elseif ($bytes -gt 1Kb) { - $size = "{0:N$decimals} Kb" -f ($bytes / 1Kb) - } else { - $size = "{0:N$decimals} b" -f $bytes - } - return $size -} -function menu-select { - ## $MainEntries should be an "AoH" object (with at least the key "Name" for each item) - ## NOTE: if the CRLF=$true; then a spacer is added before that entry. - ## Example: - ## $MainEntries = @( - ## @{Name="Windows 10 Home"; ImageFile="Win10"; ImageName="Windows 10 Home"} - ## @{Name="Windows 10 Pro"; ImageFile="Win10"; ImageName="Windows 10 Pro"} - ##) - - ## $ActionEntries should be an "AoH" object (with at least the keys "Name" and "Letter" for each item) - ## NOTE: if the CRLF=$true; then a spacer is added before that entry. - ## Example: - ## $ActionEntries = @( - ## @{Name="Reboot"; Letter="R"} - ## @{Name="Shutdown"; Letter="S"} - ##) - - param( - [string]$Title = "## Untitled Menu ##", - $MainEntries = @(), - $ActionEntries = @(), - [string]$Prompt = "Please make a selection", - [bool]$SecretExit = $false - ) - - # Bail early if no items given - if ($MainEntries.length -eq 0 -and $ActionEntries.length -eq 0) { - throw "MenuError: No items given." - } - - # Build menu - $menu_splash = "{0}`r`n`r`n" -f $title - $valid_answers = @() - if ($SecretExit) { - $valid_answers += "Q" - } - - # Add main items to splash - if ($MainEntries.length -gt 0) { - for ($i=0; $i -lt $MainEntries.length; $i++) { - if ($MainEntries[$i].CRLF) { - # Add spacer - $menu_splash += "`r`n" - } - $valid_answers += ($i + 1) - $menu_splash += "{0,2:N0}: {1}`r`n" -f ($i + 1), $MainEntries[$i].Name - } - $menu_splash += "`r`n" - } - - # Add action items to splash - if ($ActionEntries.length -gt 0) { - foreach ($_item in $ActionEntries) { - if ($_item.CRLF) { - # Add spacer - $menu_splash += "`r`n" - } - $menu_splash += " {0}: {1}`r`n" -f $_item.Letter.ToUpper(), $_item.Name - $valid_answers += $_item.Letter.ToLower(), $_item.Letter.ToUpper() - } - $menu_splash += "`r`n" - } - - # Add prompt to splash - $menu_splash += "{0}`r`n" -f $prompt - - # Select Windows version - do { - clear - $answer = read-host -prompt $menu_splash - } until ($valid_answers -contains $answer) - - return $answer.ToUpper() -} -function pause { - param([string]$message = "Press Enter to continue... ", [bool]$warning = $False) - if ($warning) { - write-host ($message) -foreground "yellow" - } else { - write-host ($message) - } - $x = read-host -} diff --git a/WK_64/Scripts/servers.ps1 b/WK_64/Scripts/servers.ps1 deleted file mode 100644 index 2d47e19f..00000000 --- a/WK_64/Scripts/servers.ps1 +++ /dev/null @@ -1,85 +0,0 @@ -# WK server functions - -## Init ## -$wd = $(Split-Path $MyInvocation.MyCommand.Path) -pushd "$wd" -. .\init.ps1 - -# Variables -$source_server = "10.0.0.10" -$backup_servers = @( - @{ "ip"="10.0.0.10"; - "letter"="Z"; - "name"="ServerOne"; - "path"="Backups"}, - @{ "ip"="10.0.0.11"; - "name"="ServerTwo"; - "letter"="Y"; - "path"="Backups"} - ) -$backup_user = "backup" -$backup_pass = "Abracadabra" - -# Functions -function select-server { - # Check for available servers - $avail_servers = @(Get-PSDrive | Where-Object {$_.DisplayRoot -imatch '\\\\'}) - if ($avail_servers.count -eq 0) { - wk-error "No suitable backup servers were detected." - return $false - } - - # Build menu and get selection - $selection = $null - $main_set = @() - foreach ($server in $avail_servers) { - $_entry = "{0} ({1} free)" -f $server.Description, (human-size $server.Free) - $main_set += @{Name=$_entry} - } - $actions = @(@{Name="Main Menu"; Letter="M"}) - $selection = (menu-select "Where are we saving the backup image(s)?" $main_set $actions) - - if ($selection -imatch '^\d+$') { - $selection -= 1 - return $avail_servers[$selection] - } - return $selection -} -function mount-servers { - # Mount servers - wk-write "Connecting to backup server(s)" - foreach ($_server in $backup_servers) { - if (test-connection $_server.ip -count 3 -quiet) { - try { - $_path = "\\{0}\{1}" -f $_server.ip, $_server.path - $_drive = "{0}:" -f $_server.letter - net use $_drive "$_path" /user:$backup_user $backup_pass | Out-Null - wk-write ("`t{0} server: mounted" -f $_server.name) - - # Add friendly description - $_regex = "^{0}$" -f $_server.letter - (Get-PSDrive | Where-Object {$_.Name -imatch $_regex}).Description = $_server.name - } catch { - wk-warn ("`t{0} server: failed" -f $_server.name) - } - } else { - wk-warn ("`t{0} server: timed-out" -f $_server.name) - } - } -} -function unmount-servers { - # Unmount servers - wk-write "Disconnecting from backup server(s)" - $mounted_servers = @(Get-PSDrive | Where-Object {$_.DisplayRoot -imatch '\\\\'}) - foreach ($_server in $mounted_servers) { - try { - $_drive = "{0}:" -f $_server.Name - net use $_drive /delete | Out-Null - #wk-warn ("`t{0} server: unmounted" -f $_server.name) - wk-warn "`tServer: unmounted" - } catch { - #wk-warn ("`t{0} server: failed" -f $_server.name) - wk-warn "`tServer: failed" - } - } -} diff --git a/make-cd.cmd b/make-cd.cmd deleted file mode 100644 index 2f7bf210..00000000 --- a/make-cd.cmd +++ /dev/null @@ -1,37 +0,0 @@ -@echo off - -:Init -setlocal EnableDelayedExpansion -title WinPE 10 creation tool -color 1b -pushd %~dp0 -set "wd=%cd%" -set "pe_iso=WinPE-2016-02d.iso" - -:Flags -for %%f in (%*) do ( - if /i "%%f" == "/DEBUG" (@echo on) -) - -:CreateISO -del "!pe_iso!" -makewinpemedia.cmd /iso "%wd%\pe_files" "!pe_iso!" -goto Done - -:Abort -echo. -echo Aborted. -goto Exit - -:Done -echo. -echo Done. -goto Exit - -:Exit -echo. -echo Press any key to exit... -pause>nul -popd -color -endlocal \ No newline at end of file diff --git a/make.cmd b/make.cmd index 5868691b..56207694 100644 --- a/make.cmd +++ b/make.cmd @@ -5,109 +5,191 @@ setlocal EnableDelayedExpansion title WinPE 10 creation tool color 1b pushd %~dp0 -set "wd=%cd%" -set "winpe_ocs=%programfiles(x86)%\Windows Kits\10\Assessment and Deployment Kit\Windows Preinstallation Environment\amd64\WinPE_OCs" -set "pe_iso=WinPE-2016-02d.iso" :Flags for %%f in (%*) do ( if /i "%%f" == "/DEBUG" (@echo on) ) -:CopyPEFiles -call copype.cmd amd64 "%wd%\pe_files" +:GetDate +:: Credit to SS64.com Code taken from http://ss64.com/nt/syntax-getdate.html +:: Use WMIC to retrieve date and time in ISO 8601 format. +FOR /F "skip=1 tokens=1-6" %%G IN ('WMIC Path Win32_LocalTime Get Day^,Hour^,Minute^,Month^,Second^,Year /Format:table') DO ( +IF "%%~L"=="" goto s_done + Set _yyyy=%%L + Set _mm=00%%J + Set _dd=00%%G + Set _hour=00%%H + SET _minute=00%%I +) +:s_done +:: Pad digits with leading zeros +Set _mm=%_mm:~-2% +Set _dd=%_dd:~-2% +Set _hour=%_hour:~-2% +Set _minute=%_minute:~-2% +Set iso_date=%_yyyy%-%_mm%-%_dd% -:Mount -rem echo Press any key to configure the WinPE image... -rem pause>nul -mkdir "%wd%\mount" -dism /mount-image /imagefile:"%wd%\pe_files\media\sources\boot.wim" /index:1 /mountdir:"%wd%\mount" +:Variables +set "wd=%cd%" +set "winpe_ocs=%programfiles(x86)%\Windows Kits\10\Assessment and Deployment Kit\Windows Preinstallation Environment" +set "pe_out=!wd!\pe_out" -:AddPackages -mkdir "%wd%\log" +:CheckForCleanup +echo Scanning for old build folders... +set "found_old=" +if exist "!wd!\mount" ( + echo. Found: "!wd!\mount" + set "found_old=true" +) +if exist "!wd!\pe_files" ( + echo. Found: "!wd!\pe_files" + set "found_old=true" +) +if defined found_old ( + goto Cleanup +) else ( + echo. No build folders found. +) +goto :BuildBoth -:: More info: https://msdn.microsoft.com/en-us/library/windows/hardware/dn938382(v=vs.85).aspx -dism /add-package /image:"%wd%\mount" /packagepath:"%winpe_ocs%\WinPE-FMAPI.cab" /logpath:"dism.log" -dism /add-package /image:"%wd%\mount" /packagepath:"%winpe_ocs%\WinPE-WMI.cab" /logpath:"dism.log" -dism /add-package /image:"%wd%\mount" /packagepath:"%winpe_ocs%\en-us\WinPE-WMI_en-us.cab" /logpath:"dism.log" +:Cleanup +echo. +choice /t 30 /c YN /d N /m "Delete the above folders?" +if %errorlevel% neq 1 goto Abort +rmdir /s /q "!wd!\mount" +rmdir /s /q "!wd!\pe_files" -:: Install WinPE-WMI before you install WinPE-NetFX. -dism /add-package /image:"%wd%\mount" /packagepath:"%winpe_ocs%\WinPE-NetFx.cab" /logpath:"dism.log" -dism /add-package /image:"%wd%\mount" /packagepath:"%winpe_ocs%\en-us\WinPE-NetFx_en-us.cab" /logpath:"dism.log" +:BuildBoth +for %%a in (amd64 x86) do ( + rem set vars + set "arch=%%a" + set "drivers=!wd!\Drivers\!arch!" + set "mount=!wd!\mount\!arch!" + set "pe_files=!wd!\pe_files\!arch!" + set "winpe_ocs=%programfiles(x86)%\Windows Kits\10\Assessment and Deployment Kit\Windows Preinstallation Environment\!arch!\WinPE_OCs" + + rem Copy main files + call copype.cmd !arch! "!pe_files!" + rmdir /s /q "!pe_files!\media\bg-bg" + rmdir /s /q "!pe_files!\media\cs-cz" + rmdir /s /q "!pe_files!\media\da-dk" + rmdir /s /q "!pe_files!\media\de-de" + rmdir /s /q "!pe_files!\media\el-gr" + rmdir /s /q "!pe_files!\media\en-gb" + rmdir /s /q "!pe_files!\media\es-es" + rmdir /s /q "!pe_files!\media\es-mx" + rmdir /s /q "!pe_files!\media\et-ee" + rmdir /s /q "!pe_files!\media\fi-fi" + rmdir /s /q "!pe_files!\media\fr-ca" + rmdir /s /q "!pe_files!\media\fr-fr" + rmdir /s /q "!pe_files!\media\hr-hr" + rmdir /s /q "!pe_files!\media\hu-hu" + rmdir /s /q "!pe_files!\media\it-it" + rmdir /s /q "!pe_files!\media\ja-jp" + rmdir /s /q "!pe_files!\media\ko-kr" + rmdir /s /q "!pe_files!\media\lt-lt" + rmdir /s /q "!pe_files!\media\lv-lv" + rmdir /s /q "!pe_files!\media\nb-no" + rmdir /s /q "!pe_files!\media\nl-nl" + rmdir /s /q "!pe_files!\media\pl-pl" + rmdir /s /q "!pe_files!\media\pt-br" + rmdir /s /q "!pe_files!\media\pt-pt" + rmdir /s /q "!pe_files!\media\ro-ro" + rmdir /s /q "!pe_files!\media\ru-ru" + rmdir /s /q "!pe_files!\media\sk-sk" + rmdir /s /q "!pe_files!\media\sl-si" + rmdir /s /q "!pe_files!\media\sr-latn-cs" + rmdir /s /q "!pe_files!\media\sr-latn-rs" + rmdir /s /q "!pe_files!\media\sv-se" + rmdir /s /q "!pe_files!\media\tr-tr" + rmdir /s /q "!pe_files!\media\uk-ua" + rmdir /s /q "!pe_files!\media\zh-cn" + rmdir /s /q "!pe_files!\media\zh-hk" + rmdir /s /q "!pe_files!\media\zh-tw" + + rem Mount Image + mkdir "!mount!" + dism /mount-image /imagefile:"!pe_files!\media\sources\boot.wim" /index:1 /mountdir:"!mount!" /logpath:"dism.log" + + rem Add Packages - More info: https://msdn.microsoft.com/en-us/library/windows/hardware/dn938382.aspx + dism /add-package /image:"!mount!" /packagepath:"!winpe_ocs!\WinPE-EnhancedStorage.cab" /logpath:"dism.log" + dism /add-package /image:"!mount!" /packagepath:"!winpe_ocs!\WinPE-FMAPI.cab" /logpath:"dism.log" + dism /add-package /image:"!mount!" /packagepath:"!winpe_ocs!\WinPE-WMI.cab" /logpath:"dism.log" + dism /add-package /image:"!mount!" /packagepath:"!winpe_ocs!\en-us\WinPE-EnhancedStorage_en-us.cab" /logpath:"dism.log" + dism /add-package /image:"!mount!" /packagepath:"!winpe_ocs!\en-us\WinPE-WMI_en-us.cab" /logpath:"dism.log" -:: Install WinPE-WMI > WinPE-NetFX before you install WinPE-Scripting. -dism /add-package /image:"%wd%\mount" /packagepath:"%winpe_ocs%\WinPE-Scripting.cab" /logpath:"dism.log" -dism /add-package /image:"%wd%\mount" /packagepath:"%winpe_ocs%\en-us\WinPE-Scripting_en-us.cab" /logpath:"dism.log" + rem Install WinPE-WMI before you install WinPE-NetFX. + dism /add-package /image:"!mount!" /packagepath:"!winpe_ocs!\WinPE-NetFx.cab" /logpath:"dism.log" + dism /add-package /image:"!mount!" /packagepath:"!winpe_ocs!\en-us\WinPE-NetFx_en-us.cab" /logpath:"dism.log" -:: Install WinPE-WMI > WinPE-NetFX > WinPE-Scripting before you install WinPE-PowerShell. -dism /add-package /image:"%wd%\mount" /packagepath:"%winpe_ocs%\WinPE-PowerShell.cab" /logpath:"dism.log" -dism /add-package /image:"%wd%\mount" /packagepath:"%winpe_ocs%\en-us\WinPE-PowerShell_en-us.cab" /logpath:"dism.log" + rem Install WinPE-WMI and WinPE-NetFX before you install WinPE-Scripting. + dism /add-package /image:"!mount!" /packagepath:"!winpe_ocs!\WinPE-Scripting.cab" /logpath:"dism.log" + dism /add-package /image:"!mount!" /packagepath:"!winpe_ocs!\en-us\WinPE-Scripting_en-us.cab" /logpath:"dism.log" -:: Install WinPE-WMI > WinPE-NetFX > WinPE-Scripting > WinPE-PowerShell before you install WinPE-DismCmdlets. -dism /add-package /image:"%wd%\mount" /packagepath:"%winpe_ocs%\WinPE-DismCmdlets.cab" /logpath:"dism.log" -dism /add-package /image:"%wd%\mount" /packagepath:"%winpe_ocs%\en-us\WinPE-DismCmdlets_en-us.cab" /logpath:"dism.log" + rem Install WinPE-WMI, WinPE-NetFX, and WinPE-Scripting before you install WinPE-PowerShell. + dism /add-package /image:"!mount!" /packagepath:"!winpe_ocs!\WinPE-PowerShell.cab" /logpath:"dism.log" + dism /add-package /image:"!mount!" /packagepath:"!winpe_ocs!\en-us\WinPE-PowerShell_en-us.cab" /logpath:"dism.log" -:: Install WinPE-WMI > WinPE-NetFX > WinPE-Scripting > WinPE-PowerShell before you install WinPE-SecureBootCmdlets. -dism /add-package /image:"%wd%\mount" /packagepath:"%winpe_ocs%\WinPE-SecureBootCmdlets.cab" /logpath:"dism.log" + rem Install WinPE-WMI, WinPE-NetFX, WinPE-Scripting, and WinPE-PowerShell before you install WinPE-DismCmdlets. + dism /add-package /image:"!mount!" /packagepath:"!winpe_ocs!\WinPE-DismCmdlets.cab" /logpath:"dism.log" + dism /add-package /image:"!mount!" /packagepath:"!winpe_ocs!\en-us\WinPE-DismCmdlets_en-us.cab" /logpath:"dism.log" -:: Install WinPE-WMI > WinPE-NetFX > WinPE-Scripting > WinPE-PowerShell before you install WinPE-StorageWMI. -dism /add-package /image:"%wd%\mount" /packagepath:"%winpe_ocs%\WinPE-StorageWMI.cab" /logpath:"dism.log" -dism /add-package /image:"%wd%\mount" /packagepath:"%winpe_ocs%\en-us\WinPE-StorageWMI_en-us.cab" /logpath:"dism.log" + rem Install WinPE-WMI, WinPE-NetFX, WinPE-Scripting, and WinPE-PowerShell before you install WinPE-SecureBootCmdlets. + dism /add-package /image:"!mount!" /packagepath:"!winpe_ocs!\WinPE-SecureBootCmdlets.cab" /logpath:"dism.log" -:: Install ?? before you install WinPE-EnhancedStorage. -dism /add-package /image:"%wd%\mount" /packagepath:"%winpe_ocs%\WinPE-EnhancedStorage.cab" /logpath:"dism.log" -dism /add-package /image:"%wd%\mount" /packagepath:"%winpe_ocs%\en-us\WinPE-EnhancedStorage_en-us.cab" /logpath:"dism.log" + rem Install WinPE-WMI, WinPE-NetFX, WinPE-Scripting, and WinPE-PowerShell before you install WinPE-StorageWMI. + dism /add-package /image:"!mount!" /packagepath:"!winpe_ocs!\WinPE-StorageWMI.cab" /logpath:"dism.log" + dism /add-package /image:"!mount!" /packagepath:"!winpe_ocs!\en-us\WinPE-StorageWMI_en-us.cab" /logpath:"dism.log" + + rem Add Drivers + dism /add-driver /image:"!mount!" /driver:"!drivers!" /recurse /logpath:"dism.log" + + rem Force RamDisk size to try and avoid capture-image errors + dism /image:"!mount!" /set-scratchspace:512 + + rem Add WK Stuff + del "!wd!\WK\Scripts\WK.log" + mkdir "!mount!\WK" + robocopy /s /r:3 /w:0 "!wd!\WK\!arch!" "!mount!\WK" + mkdir "!mount!\WK\Scripts" + robocopy /s /r:3 /w:0 "!wd!\Scripts" "!mount!\WK\Scripts" + + rem Add System32 Stuff + copy /y "!wd!\System32\menu.cmd" "!mount!\Windows\System32\menu.cmd" + copy /y "!wd!\System32\Winpeshl.ini" "!mount!\Windows\System32\Winpeshl.ini" + + rem Background + takeown /f "!mount!\Windows\System32\winpe.jpg" /a + icacls "!mount!\Windows\System32\winpe.jpg" /grant administrators:F + copy /y "!wd!\System32\winpe.jpg" "!mount!\Windows\System32\winpe.jpg" + copy /y "!wd!\System32\winpe.jpg" "!mount!\WK\ConEmu\winpe.jpg" + + rem Registry Edits + reg load HKLM\WinPE-SW "!mount!\Windows\System32\config\SOFTWARE" + reg load HKLM\WinPE-SYS "!mount!\Windows\System32\config\SYSTEM" + + rem Add 7-Zip to path + reg add "HKLM\WinPE-SYS\ControlSet001\Control\Session Manager\Environment" /v Path /t REG_EXPAND_SZ /d "%%SystemRoot%%\system32;%%SystemRoot%%;%%SystemRoot%%\System32\Wbem;%%SYSTEMROOT%%\System32\WindowsPowerShell\v1.0\;%%SystemDrive%%\WK\7-Zip" /f -:Robocopy -del "%wd%\WK\Scripts\WK.log" -mkdir "%wd%\mount\WK" -robocopy /e "%wd%\WK" "%wd%\mount\WK" -del "%wd%\mount\Windows\explorer.exe" -mklink /h "%wd%\mount\Windows\explorer.exe" "%wd%\mount\WK\Explorer++\Explorer++64.exe" + rem Replace Notepad + reg add "HKLM\WinPE-SW\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\notepad.exe" /v Debugger /t REG_SZ /d "X:\WK\Notepad2\Notepad2-Mod.exe /z" /f -:System32Stuff -copy /y "%wd%\System32\menu.cmd" "%wd%\mount\Windows\System32\menu.cmd" -copy /y "%wd%\System32\Winpeshl.ini" "%wd%\mount\Windows\System32\Winpeshl.ini" - -:RegistryEdits -reg load HKLM\WinPE-SW mount\Windows\System32\config\SOFTWARE -reg load HKLM\WinPE-SYS mount\Windows\System32\config\SYSTEM - -rem Add 7-Zip to path -reg add "HKLM\WinPE-SYS\ControlSet001\Control\Session Manager\Environment" /v Path /t REG_EXPAND_SZ /d "%%SystemRoot%%\system32;%%SystemRoot%%;%%SystemRoot%%\System32\Wbem;%%SYSTEMROOT%%\System32\WindowsPowerShell\v1.0\;%%SystemDrive%%\WK\7-Zip" /f - -rem Replace Notepad -reg add "HKLM\WinPE-SW\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\notepad.exe" /v Debugger /t REG_SZ /d "X:\WK\Notepad2\Notepad2-Mod64.exe /z" /f - -rem Unload registry hives -reg unload HKLM\WinPE-SW -reg unload HKLM\WinPE-SYS - -:Background -takeown /f "%wd%\mount\Windows\System32\winpe.jpg" /a -icacls "%wd%\mount\Windows\System32\winpe.jpg" /grant administrators:F -copy /y "%wd%\System32\winpe.jpg" "%wd%\mount\Windows\System32\winpe.jpg" -copy /y "%wd%\System32\winpe.jpg" "%wd%\mount\WK\ConEmu\winpe.jpg" - -:ManualStuff -REM echo Now is the time to add stuff (optional). -REM echo. -REM echo Press any key to commit changes... -REM pause>nul - -:Set-ScratchSpace -rem Force RamDisk size to try and avoid capture-image errors -dism /image:"%wd%\mount" /set-scratchspace:512 - -:Unmount -dism /unmount-image /mountdir:"%wd%\mount" /commit - -:CreateISO -del "!pe_iso!" -makewinpemedia.cmd /iso "%wd%\pe_files" "!pe_iso!" + rem Unload registry hives + reg unload HKLM\WinPE-SW + reg unload HKLM\WinPE-SYS + + rem Unmount Image + dism /unmount-image /mountdir:"!mount!" /commit + + rem Create ISO + del "WinPE-!iso_date!-!arch!.iso" + call makewinpemedia.cmd /iso "!pe_files!" "WinPE-!iso_date!-!arch!.iso" +) goto Done :Abort +color 4e echo. echo Aborted. goto Exit