Added Build PE.cmd launch script
* Checks for elevation and relaunches script if necessary * Checks for WADK installation and loads DandISetEnv.bat * This sets the proper variables * Runs PowerShell in the same window to preserve DandI vars
This commit is contained in:
parent
b8a088d3b6
commit
1e41954f62
3 changed files with 190 additions and 2 deletions
71
.bin/Scripts/build_pe.ps1
Normal file
71
.bin/Scripts/build_pe.ps1
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
# Wizard Kit: Windows PE Build Tool
|
||||
|
||||
## Init ##
|
||||
#Requires -Version 3.0
|
||||
#Requires -RunAsAdministrator
|
||||
clear
|
||||
$host.UI.RawUI.WindowTitle = "Wizard Kit: Windows PE Build Tool"
|
||||
$wd = $(Split-Path $MyInvocation.MyCommand.Path)
|
||||
$bin = (Get-Item $wd -Force).Parent.FullName
|
||||
$root = (Get-Item $bin -Force).Parent.FullName
|
||||
$tmp = "{0}\tmp" -f $bin
|
||||
$errors = 0
|
||||
pushd "$wd"
|
||||
$host.UI.RawUI.BackgroundColor = "black"
|
||||
$host.UI.RawUI.ForegroundColor = "white"
|
||||
$progressPreference = 'silentlyContinue'
|
||||
# clear
|
||||
foreach ($v in @('SystemDrive', 'USERPROFILE', 'DISMRoot', 'BCDBootRoot', 'ImagingRoot', 'OSCDImgRoot', 'WdsmcastRoot')) {
|
||||
write-host ('{0}: {1}' -f $v, (gci env:$v).value)
|
||||
}
|
||||
write-host ""
|
||||
write-host ("wd: {0}" -f $wd)
|
||||
write-host ("bin: {0}" -f $bin)
|
||||
write-host ("root: {0}" -f $root)
|
||||
write-host ("tmp: {0}" -f $tmp)
|
||||
read-host "Bananas?"
|
||||
exit
|
||||
|
||||
## Functions ##
|
||||
function download-file {
|
||||
param ([String]$path, [String]$name, [String]$url)
|
||||
$outfile = "{0}\{1}" -f $path, $name
|
||||
|
||||
Write-Host ("Downloading: {0}" -f $name)
|
||||
New-Item -Type Directory $path 2>&1 | Out-Null
|
||||
try {
|
||||
invoke-webrequest -uri $url -outfile $outfile
|
||||
}
|
||||
catch {
|
||||
Write-Host (" ERROR: Failed to download file." ) -foregroundcolor "Red"
|
||||
$errors += 1
|
||||
}
|
||||
}
|
||||
function find-dynamic-url {
|
||||
param ([String]$source_page, [String]$regex)
|
||||
$d_url = ""
|
||||
|
||||
# Get source page
|
||||
invoke-webrequest -uri $source_page -outfile "tmp_page"
|
||||
|
||||
# Search for real url
|
||||
$d_url = Get-Content "tmp_page" | Where-Object {$_ -imatch $regex}
|
||||
$d_url = $d_url -ireplace '.*(a |)href="([^"]+)".*', '$2'
|
||||
$d_url = $d_url -ireplace ".*(a |)href='([^']+)'.*", '$2'
|
||||
|
||||
# Remove tmp_page
|
||||
Remove-Item "tmp_page"
|
||||
|
||||
return $d_url
|
||||
}
|
||||
function wk_pause {
|
||||
param([string]$message = "Press Enter to continue... ")
|
||||
Write-Host $message
|
||||
$x = read-host
|
||||
}
|
||||
|
||||
## Build ##
|
||||
# TODO #
|
||||
|
||||
## Done ##
|
||||
popd
|
||||
8
.gitignore
vendored
8
.gitignore
vendored
|
|
@ -1,5 +1,9 @@
|
|||
*iso
|
||||
*.bak
|
||||
*.iso
|
||||
.bin/Scripts/__pycache__
|
||||
.bin/tmp
|
||||
Drivers
|
||||
Logs
|
||||
Scripts/__pycache__
|
||||
dism*
|
||||
mount
|
||||
pe_files
|
||||
113
Build PE.cmd
Normal file
113
Build PE.cmd
Normal file
|
|
@ -0,0 +1,113 @@
|
|||
:: Wizard Kit: Windows PE Build Tool Launcher ::
|
||||
|
||||
@echo off
|
||||
|
||||
:Init
|
||||
setlocal EnableDelayedExpansion
|
||||
title Wizard Kit: Windows PE Build Tool
|
||||
call :CheckFlags %*
|
||||
call :CheckElevation || goto Exit
|
||||
call :FindKitsRoot || goto ErrorKitNotFound
|
||||
set "dandi_set_env=%adk_root%\Deployment Tools\DandISetEnv.bat"
|
||||
set "ps_script=%~dp0\.bin\Scripts\build_pe.ps1"
|
||||
|
||||
:LaunchPrep
|
||||
rem Verify scripts exists
|
||||
if not exist "%dandi_set_env%" (goto ErrorKitNotFound)
|
||||
if not exist "%ps_script%" (goto ErrorPSScriptMissing)
|
||||
call "%dandi_set_env%" || goto ErrorUnknown
|
||||
|
||||
:Launch
|
||||
PowerShell -ExecutionPolicy bypass -File %ps_script%"
|
||||
goto Exit
|
||||
|
||||
:: Functions ::
|
||||
:CheckElevation
|
||||
rem Code based on StackOverflow comments
|
||||
rem Question: https://stackoverflow.com/q/4051883
|
||||
rem Using answer: https://stackoverflow.com/a/21295806
|
||||
rem Asked by: https://stackoverflow.com/users/272237/flacs
|
||||
rem Edited by: https://stackoverflow.com/users/330315/a-horse-with-no-name
|
||||
rem Answer by: https://stackoverflow.com/users/3198799/and31415
|
||||
fsutil dirty query %systemdrive% >nul
|
||||
if %errorlevel% neq 0 (
|
||||
call :RequestElevation
|
||||
rem reset errorlevel to 1 to abort the current non-elevated script
|
||||
color 00
|
||||
)
|
||||
@exit /b %errorlevel%
|
||||
|
||||
:CheckFlags
|
||||
rem Loops through all arguments to check for accepted flags
|
||||
set DEBUG=
|
||||
for %%f in (%*) do (
|
||||
if /i "%%f" == "/DEBUG" (@echo on & set "DEBUG=/DEBUG")
|
||||
)
|
||||
@exit /b 0
|
||||
|
||||
:FindKitsRoot
|
||||
set "adk_root="
|
||||
set "found="
|
||||
set "r_vname=KitsRoot10"
|
||||
|
||||
rem Check registry for WADK
|
||||
set "r_path=HKLM\Software\Wow6432Node\Microsoft\Windows Kits\Installed Roots"
|
||||
reg query "%r_path%" /v %r_vname% >nul 2>&1 && set "found=True"
|
||||
if not defined found (
|
||||
rem 32-bit systems?
|
||||
set "r_path=HKLM\Software\Microsoft\Windows Kits\Installed Roots"
|
||||
reg query "!r_path!" /v %r_vname% >nul 2>&1 && set "found=True"
|
||||
)
|
||||
for /f "skip=2 tokens=2*" %%i in ('reg query "%r_path%" /v %r_vname%') do (
|
||||
set adk_root=%%j\Assessment and Deployment Kit
|
||||
)
|
||||
rem Set errorlevel if necessary
|
||||
if not defined adk_root color 00
|
||||
if not defined found color 00
|
||||
@exit /b %errorlevel%
|
||||
|
||||
:RequestElevation
|
||||
set "cscript=%systemroot%\system32\cscript.exe"
|
||||
set "vb_script=.bin\tmp\Elevate.vbs"
|
||||
mkdir ".bin\tmp" 2>nul
|
||||
|
||||
rem Create VB script
|
||||
echo Set UAC = CreateObject^("Shell.Application"^) > "%vb_script%"
|
||||
echo UAC.ShellExecute "%~s0", "", "", "runas", 3 >> "%vb_script%"
|
||||
|
||||
rem Run
|
||||
"%cscript%" //nologo "%vb_script%" || goto ErrorUnknown
|
||||
del "%vb_script%"
|
||||
@exit /b 0
|
||||
|
||||
:: Errors ::
|
||||
:ErrorKitNotFound
|
||||
echo.
|
||||
echo ERROR: Windows ADK installation not found.
|
||||
goto Abort
|
||||
|
||||
:ErrorPSScriptMissing
|
||||
echo.
|
||||
echo ERROR: build_pe.ps1 script not found.
|
||||
goto Abort
|
||||
|
||||
:ErrorUnknown
|
||||
echo.
|
||||
echo ERROR: Encountered an unknown error.
|
||||
goto Abort
|
||||
|
||||
:Abort
|
||||
color 4e
|
||||
echo Aborted.
|
||||
echo.
|
||||
echo Press any key to exit...
|
||||
pause>nul
|
||||
color
|
||||
rem Set errorlevel to 1 by calling color incorrectly
|
||||
color 00
|
||||
goto Exit
|
||||
|
||||
:: Cleanup and exit ::
|
||||
:Exit
|
||||
endlocal
|
||||
exit /b %errorlevel%
|
||||
Loading…
Reference in a new issue