von Holgi » 30.10.2023, 17:22
			
			
			Ich habe das Script nochmals etwas überarbeitet:
hinzugekommen ist die Möglichkeit, auch einen USB Stick mit WINPE (und ggf. DriveSnapshot) zu versehen.
Darüberhinaus kann man jetzt auch die unnötigen Sprachpakete-Ordner (bis auf DE und EN) löschen.
Letztlich wurde die Reihenfolge etwas mehr der Logik der einzelnen Schritte angepasst.
Wer also noch keine WINPE Workbench hat, wird normalerweise die Schritte A (Create PE Image) bis I (Commit and Unmount Image) durchführen. Erst dann muss man sich entweder für die ISO Erstellung (K) oder Erstellung eines USB Sticks (L) entscheiden.
makeWinpe.bat
Code: Alles auswählen
@ECHO OFF
COLOR 0a
::script tool to create, mount, commit, build ISOs for WinPE
SET default_img_dir=C:\WinPE_amd64
:: change this to your directory of choice for convience
SET adk_dir="C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Deployment Tools"
SET adk_env="C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Deployment Tools\DandISetEnv.bat"
:: where ADK is installed
:: download the latest ADK below
:: https://docs.microsoft.com/en-us/windows-hardware/get-started/adk-install
CD %adk_dir%
CALL %adk_env%
:: necessary for running copype & MakeWinPEMedia command within script
REM ###############################################################################
:: set initial directory to be used
:SetDir
CLS
SET img_dir=%default_img_dir%
SET choice=
SET /P choice=Zielverzeichnis vorgeben [%img_dir%]: 
IF NOT '%choice%'=='' SET img_dir=%choice%
ECHO.
ECHO using "%img_dir%" as image directory
SET choice=
SET /P choice=continue? [y]: 
IF /I '%choice%'=='Y' GOTO LOOP
GOTO SetDir
REM ###############################################################################
:: main menu
:LOOP
CLS
::  ____   ____  _  _  _  ____  ___  _  _   ___   ____  ___  _   _  _____  _____ 
:: |: _ \ |: _ \|.|( \/ )|:___)/.__)|:\|:| / _ \ |: _ \/.__)|.|_|.||. _ .||_ . _|
:: |:|_) )|:   /|:| \::/ |:__) \__.\|:\ :||: _ :||:___/\__.\|: _ :||:|_|:|  |:|
:: |____/ |_|\_\|_|  \/  |____)(___/|_|\_||_| |_||_|   (___/|_| |_||_____|  |_|
::
ECHO ###########################################
ECHO #   A. Create PE Image                    #
ECHO #   B. Mount Image                        #
ECHO #   C. Implement German Language (opt)    #
ECHO #   D. Del Languages except DE/EN (opt)   #
ECHO #   E. Download DriveSnapshot (opt)       #
ECHO #   F. Copy DriveSnapshot to PE (opt)     #
ECHO #   G. Modify Startnet.cmd (opt)          #
ECHO #   H. Remove "Press any Key to boot"(opt)#
ECHO #   I. Commit and Unmount Image           #
ECHO #   K. Build ISO                          #
ECHO #   L. Build USB Stick                    #
ECHO #   M. Discard and Unmount Image          #
ECHO #   N. Cleanup WIM                        #
ECHO #   O. Delete Folders                     #
ECHO #   Q. Quit                               #
ECHO ###########################################
ECHO.
SET choice=
SET /P choice=select option: 
CLS
:: /I makes the IF comparison case-insensitive
IF /I '%choice%'=='A' GOTO CreatePE
IF /I '%choice%'=='B' GOTO MOUNT
IF /I '%choice%'=='C' GOTO German
IF /I '%choice%'=='D' GOTO Languages
IF /I '%choice%'=='E' GOTO Download
IF /I '%choice%'=='F' GOTO CopySnapshot
IF /I '%choice%'=='G' GOTO Startnet
IF /I '%choice%'=='H' GOTO AnyKey
IF /I '%choice%'=='I' GOTO COMMIT
IF /I '%choice%'=='K' GOTO ISO
IF /I '%choice%'=='L' GOTO USB
IF /I '%choice%'=='M' GOTO Discard
IF /I '%choice%'=='N' GOTO CleanUP
IF /I '%choice%'=='O' GOTO Delete
IF /I '%choice%'=='Q' EXIT
ECHO invalid input!
PAUSE
GOTO LOOP
REM ###############################################################################
:: mount an WinPE enviornment
:: mounts within image directory within subfolder "mount"
:MOUNT
ECHO loading image and mounting
SET img_file=%img_dir%\media\sources\boot.wim
SET mount_dir=%img_dir%\mount
SET index=1
CALL Dism /Mount-Image /ImageFile:%img_file% /index:%index% /MountDir:%mount_dir%
PAUSE
GOTO LOOP
REM ###############################################################################
:: commit changes made to a mounted image and then unmount
:COMMIT
ECHO committing and unmounting...
CALL Dism /Unmount-Image /MountDir:%mount_dir% /commit
PAUSE
GOTO LOOP
REM ###############################################################################
:: discard changes made to a mounted image and then unmount
:DISCARD
SET mount_dir=%img_dir%\mount
ECHO discarding and unmounting...
CALL Dism /Unmount-Image /MountDir:%mount_dir% /discard
PAUSE
GOTO LOOP
REM ###############################################################################
:ISO
:: create a bootable ISO of your WinPE enviornment
:: https://learn.microsoft.com/en-us/windows-hardware/manufacture/desktop/winpe-create-usb-bootable-drive?view=windows-11#create-a-winpe-iso-dvd-or-cd
ECHO building ISO...
SET iso_file=WinPE_amd64_Snapshot.iso
CALL MakeWinPEMedia /ISO /f %img_dir% %img_dir%\%iso_file%
PAUSE
GOTO LOOP
REM ###############################################################################
:CreatePE
SET ark=amd64
:: define arktecture
:: Specify either x86, amd64, or arm
ECHO creating WinPE image at "%img_dir%"
CALL copype %ark% %img_dir%
:: img_dir should not already exist
PAUSE
GOTO LOOP
REM ###############################################################################
:Download
SET "FILENAME=%~dp0\Snapshot64.exe"
bitsadmin.exe /transfer "Snapshot64.exe" /download /priority foreground "http://www.drivesnapshot.de/download/snapshot64.exe" "%FILENAME%"
cls
Echo Download completed!!
PAUSE
GOTO LOOP
REM ###############################################################################
:CopySnapshot
SET mount_dir=%img_dir%\mount
SET FILENAME="%~dp0\Snapshot64.exe"
if not exist %mount_dir%\Tools\Snapshot md %mount_dir%\Tools\Snapshot
copy /y %Filename% %mount_dir%\Tools\Snapshot\ 
Echo Snapshot64.exe copied to mount Directory 
PAUSE
GOTO LOOP
REM ###############################################################################
:Startnet
SET mount_dir=%img_dir%\mount
@echo off
ver
set start=%mount_dir%\Windows\System32\startnet.cmd
>"%start%" echo wpeinit
>>"%start%" echo @echo off
>>"%start%" echo wpeutil InitializeNetwork
>>"%start%" echo wpeutil SetKeyboardLayout 0407:00000407
>>"%start%" echo start "" "X:\Tools\Snapshot\snapshot64.exe"
Echo Startnet Bearbeitung fertig! 
PAUSE
GOTO LOOP
REM ###############################################################################
:Cleanup
SET mount_dir=%img_dir%\mount
dism /cleanup-wim
Echo WIM Cleanup erledigt!
PAUSE
GOTO LOOP
REM ###############################################################################
:Delete
RD %img_dir% /s /q
Echo WINPE Folder removed!
PAUSE
GOTO LOOP
REM ###############################################################################
:AnyKey
copy /y "%ProgramFiles(x86)%\Windows Kits\10\Assessment and Deployment Kit\Deployment Tools\amd64\Oscdimg\efisys_noprompt.bin" "%img_dir%\fwfiles/efisys.bin"
Echo AnyKey removed!
PAUSE
GOTO LOOP
REM ###############################################################################
:German
SET mount_dir=%img_dir%\mount
dism /image:%mount_dir% /add-package /packagepath:"%ProgramFiles(x86)%\Windows Kits\10\Assessment and Deployment Kit\Windows Preinstallation Environment\amd64\WinPE_OCs\de-de\lp.cab"
cls
dism /image:%mount_dir% /set-allintl:de-DE
cls
Echo German Language installed!
PAUSE
GOTO LOOP
REM ###############################################################################
:USB
:: Create a bootable Windows PE USB drive
:: https://learn.microsoft.com/en-us/windows-hardware/manufacture/desktop/winpe-create-usb-bootable-drive?view=windows-11#create-a-bootable-windows-pe-usb-drive
Echo please insert USB Stick into USB port if not already done
Echo check Explorer for USB Drive Letter
set /p dl="Enter drive letter for your USB Drive: "
ECHO building USB...
CALL MakeWinPEMedia /UFD /f %img_dir% %dl%:
cls
echo WinPE USB Drive created!
PAUSE
GOTO LOOP
REM ###############################################################################
:Languages
:: delete all Languages except German & english (US)
cd %default_img_dir%\media
rmdir bg-BG /s /q
rmdir cs-CZ /s /q
rmdir da-DK /s /q
rmdir el-GR /s /q
rmdir en-GB /s /q
rmdir es-ES /s /q
rmdir es-MX /s /q
rmdir et-EE /s /q
rmdir fi-FI /s /q
rmdir fr-CA /s /q
rmdir fr-FR /s /q
rmdir hr-HR /s /q
rmdir hu-HU /s /q
rmdir it-IT /s /q
rmdir ja-jp /s /q
rmdir ko-KR /s /q
rmdir lt-LT /s /q
rmdir lv-LV /s /q
rmdir nb-NO /s /q
rmdir nl-NL /s /q
rmdir pl-PL /s /q
rmdir pt-BR /s /q
rmdir pt-PT /s /q
rmdir ro-RO /s /q
rmdir ru-RU /s /q
rmdir sk-SK /s /q
rmdir sl-SI /s /q
rmdir sr-Latn-RS /s /q
rmdir sv-SE /s /q
rmdir tr-TR /s /q
rmdir uk-UA /s /q
rmdir zh-CN /s /q
rmdir zh-TW /s /q
cls
Echo Languages deleted!
PAUSE
GOTO LOOP
Viel Spaß! Feedback welcome
 
			
			
							Ich habe das Script nochmals etwas überarbeitet:
hinzugekommen ist die Möglichkeit, auch einen USB Stick mit WINPE (und ggf. DriveSnapshot) zu versehen.
Darüberhinaus kann man jetzt auch die unnötigen Sprachpakete-Ordner (bis auf DE und EN) löschen.
Letztlich wurde die Reihenfolge etwas mehr der Logik der einzelnen Schritte angepasst.
Wer also noch keine WINPE Workbench hat, wird normalerweise die Schritte A (Create PE Image) bis I (Commit and Unmount Image) durchführen. Erst dann muss man sich entweder für die ISO Erstellung (K) oder Erstellung eines USB Sticks (L) entscheiden.
makeWinpe.bat
[code]@ECHO OFF
COLOR 0a
::script tool to create, mount, commit, build ISOs for WinPE
SET default_img_dir=C:\WinPE_amd64
:: change this to your directory of choice for convience
SET adk_dir="C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Deployment Tools"
SET adk_env="C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Deployment Tools\DandISetEnv.bat"
:: where ADK is installed
:: download the latest ADK below
:: https://docs.microsoft.com/en-us/windows-hardware/get-started/adk-install
CD %adk_dir%
CALL %adk_env%
:: necessary for running copype & MakeWinPEMedia command within script
REM ###############################################################################
:: set initial directory to be used
:SetDir
CLS
SET img_dir=%default_img_dir%
SET choice=
SET /P choice=Zielverzeichnis vorgeben [%img_dir%]: 
IF NOT '%choice%'=='' SET img_dir=%choice%
ECHO.
ECHO using "%img_dir%" as image directory
SET choice=
SET /P choice=continue? [y]: 
IF /I '%choice%'=='Y' GOTO LOOP
GOTO SetDir
REM ###############################################################################
:: main menu
:LOOP
CLS
::  ____   ____  _  _  _  ____  ___  _  _   ___   ____  ___  _   _  _____  _____ 
:: |: _ \ |: _ \|.|( \/ )|:___)/.__)|:\|:| / _ \ |: _ \/.__)|.|_|.||. _ .||_ . _|
:: |:|_) )|:   /|:| \::/ |:__) \__.\|:\ :||: _ :||:___/\__.\|: _ :||:|_|:|  |:|
:: |____/ |_|\_\|_|  \/  |____)(___/|_|\_||_| |_||_|   (___/|_| |_||_____|  |_|
::
ECHO ###########################################
ECHO #   A. Create PE Image                    #
ECHO #   B. Mount Image                        #
ECHO #   C. Implement German Language (opt)    #
ECHO #   D. Del Languages except DE/EN (opt)   #
ECHO #   E. Download DriveSnapshot (opt)       #
ECHO #   F. Copy DriveSnapshot to PE (opt)     #
ECHO #   G. Modify Startnet.cmd (opt)          #
ECHO #   H. Remove "Press any Key to boot"(opt)#
ECHO #   I. Commit and Unmount Image           #
ECHO #   K. Build ISO                          #
ECHO #   L. Build USB Stick                    #
ECHO #   M. Discard and Unmount Image          #
ECHO #   N. Cleanup WIM                        #
ECHO #   O. Delete Folders                     #
ECHO #   Q. Quit                               #
ECHO ###########################################
ECHO.
SET choice=
SET /P choice=select option: 
CLS
:: /I makes the IF comparison case-insensitive
IF /I '%choice%'=='A' GOTO CreatePE
IF /I '%choice%'=='B' GOTO MOUNT
IF /I '%choice%'=='C' GOTO German
IF /I '%choice%'=='D' GOTO Languages
IF /I '%choice%'=='E' GOTO Download
IF /I '%choice%'=='F' GOTO CopySnapshot
IF /I '%choice%'=='G' GOTO Startnet
IF /I '%choice%'=='H' GOTO AnyKey
IF /I '%choice%'=='I' GOTO COMMIT
IF /I '%choice%'=='K' GOTO ISO
IF /I '%choice%'=='L' GOTO USB
IF /I '%choice%'=='M' GOTO Discard
IF /I '%choice%'=='N' GOTO CleanUP
IF /I '%choice%'=='O' GOTO Delete
IF /I '%choice%'=='Q' EXIT
ECHO invalid input!
PAUSE
GOTO LOOP
REM ###############################################################################
:: mount an WinPE enviornment
:: mounts within image directory within subfolder "mount"
:MOUNT
ECHO loading image and mounting
SET img_file=%img_dir%\media\sources\boot.wim
SET mount_dir=%img_dir%\mount
SET index=1
CALL Dism /Mount-Image /ImageFile:%img_file% /index:%index% /MountDir:%mount_dir%
PAUSE
GOTO LOOP
REM ###############################################################################
:: commit changes made to a mounted image and then unmount
:COMMIT
ECHO committing and unmounting...
CALL Dism /Unmount-Image /MountDir:%mount_dir% /commit
PAUSE
GOTO LOOP
REM ###############################################################################
:: discard changes made to a mounted image and then unmount
:DISCARD
SET mount_dir=%img_dir%\mount
ECHO discarding and unmounting...
CALL Dism /Unmount-Image /MountDir:%mount_dir% /discard
PAUSE
GOTO LOOP
REM ###############################################################################
:ISO
:: create a bootable ISO of your WinPE enviornment
:: https://learn.microsoft.com/en-us/windows-hardware/manufacture/desktop/winpe-create-usb-bootable-drive?view=windows-11#create-a-winpe-iso-dvd-or-cd
ECHO building ISO...
SET iso_file=WinPE_amd64_Snapshot.iso
CALL MakeWinPEMedia /ISO /f %img_dir% %img_dir%\%iso_file%
PAUSE
GOTO LOOP
REM ###############################################################################
:CreatePE
SET ark=amd64
:: define arktecture
:: Specify either x86, amd64, or arm
ECHO creating WinPE image at "%img_dir%"
CALL copype %ark% %img_dir%
:: img_dir should not already exist
PAUSE
GOTO LOOP
REM ###############################################################################
:Download
SET "FILENAME=%~dp0\Snapshot64.exe"
bitsadmin.exe /transfer "Snapshot64.exe" /download /priority foreground "http://www.drivesnapshot.de/download/snapshot64.exe" "%FILENAME%"
cls
Echo Download completed!!
PAUSE
GOTO LOOP
REM ###############################################################################
:CopySnapshot
SET mount_dir=%img_dir%\mount
SET FILENAME="%~dp0\Snapshot64.exe"
if not exist %mount_dir%\Tools\Snapshot md %mount_dir%\Tools\Snapshot
copy /y %Filename% %mount_dir%\Tools\Snapshot\ 
Echo Snapshot64.exe copied to mount Directory 
PAUSE
GOTO LOOP
REM ###############################################################################
:Startnet
SET mount_dir=%img_dir%\mount
@echo off
ver
set start=%mount_dir%\Windows\System32\startnet.cmd
>"%start%" echo wpeinit
>>"%start%" echo @echo off
>>"%start%" echo wpeutil InitializeNetwork
>>"%start%" echo wpeutil SetKeyboardLayout 0407:00000407
>>"%start%" echo start "" "X:\Tools\Snapshot\snapshot64.exe"
Echo Startnet Bearbeitung fertig! 
PAUSE
GOTO LOOP
REM ###############################################################################
:Cleanup
SET mount_dir=%img_dir%\mount
dism /cleanup-wim
Echo WIM Cleanup erledigt!
PAUSE
GOTO LOOP
REM ###############################################################################
:Delete
RD %img_dir% /s /q
Echo WINPE Folder removed!
PAUSE
GOTO LOOP
REM ###############################################################################
:AnyKey
copy /y "%ProgramFiles(x86)%\Windows Kits\10\Assessment and Deployment Kit\Deployment Tools\amd64\Oscdimg\efisys_noprompt.bin" "%img_dir%\fwfiles/efisys.bin"
Echo AnyKey removed!
PAUSE
GOTO LOOP
REM ###############################################################################
:German
SET mount_dir=%img_dir%\mount
dism /image:%mount_dir% /add-package /packagepath:"%ProgramFiles(x86)%\Windows Kits\10\Assessment and Deployment Kit\Windows Preinstallation Environment\amd64\WinPE_OCs\de-de\lp.cab"
cls
dism /image:%mount_dir% /set-allintl:de-DE
cls
Echo German Language installed!
PAUSE
GOTO LOOP
REM ###############################################################################
:USB
:: Create a bootable Windows PE USB drive
:: https://learn.microsoft.com/en-us/windows-hardware/manufacture/desktop/winpe-create-usb-bootable-drive?view=windows-11#create-a-bootable-windows-pe-usb-drive
Echo please insert USB Stick into USB port if not already done
Echo check Explorer for USB Drive Letter
set /p dl="Enter drive letter for your USB Drive: "
ECHO building USB...
CALL MakeWinPEMedia /UFD /f %img_dir% %dl%:
cls
echo WinPE USB Drive created!
PAUSE
GOTO LOOP
REM ###############################################################################
:Languages
:: delete all Languages except German & english (US)
cd %default_img_dir%\media
rmdir bg-BG /s /q
rmdir cs-CZ /s /q
rmdir da-DK /s /q
rmdir el-GR /s /q
rmdir en-GB /s /q
rmdir es-ES /s /q
rmdir es-MX /s /q
rmdir et-EE /s /q
rmdir fi-FI /s /q
rmdir fr-CA /s /q
rmdir fr-FR /s /q
rmdir hr-HR /s /q
rmdir hu-HU /s /q
rmdir it-IT /s /q
rmdir ja-jp /s /q
rmdir ko-KR /s /q
rmdir lt-LT /s /q
rmdir lv-LV /s /q
rmdir nb-NO /s /q
rmdir nl-NL /s /q
rmdir pl-PL /s /q
rmdir pt-BR /s /q
rmdir pt-PT /s /q
rmdir ro-RO /s /q
rmdir ru-RU /s /q
rmdir sk-SK /s /q
rmdir sl-SI /s /q
rmdir sr-Latn-RS /s /q
rmdir sv-SE /s /q
rmdir tr-TR /s /q
rmdir uk-UA /s /q
rmdir zh-CN /s /q
rmdir zh-TW /s /q
cls
Echo Languages deleted!
PAUSE
GOTO LOOP[/code]
Viel Spaß! Feedback welcome