Solved Compress Batch file code. DISM apply/diskpart

Sandisk 8gb cruzer usb 2.0 flash drive
December 13, 2013 at 00:18:22
Specs: Windows 8.1 Pro x64, Intel i5 (3rd Gen) / 16Gb
I've written this to run from Windows PE to apply image.wim files for Windows. It installs Windows Vista, 7, 8, and 8.1 - Either x64 or x86 bit.

Also, I am having trouble figuring out how to get GPT/UEFI scripted into this.

I am looking for assistance from anyone that can show me how to either compress the code or improve upon it. I am limited to batch cause that is all I know how to write :/

Right now it should only be used with computers that contain only 1 HDD cause it just selects the first HDD and writes over what ever is there. Diskpart clean and new partition is created.

CODE
-------------------------------------------------
:: InstallOS.CMD v0.8
:: Written by: Humphrey
::
:: Runs from Windows PE to create partitions, apply a Windows image file, and setup the boot record.
@ECHO OFF
::SETUP
SetLocal EnableDelayedExpansion
SET IMGDIR=.\Images\
CD /D %~dp0
:Main
::Main Menu / OS Selection
TITLE Select Which Windows OS To Install
ECHO.
ECHO. Select which Windows version to install.
ECHO.
ECHO. 1] Windows Vista
ECHO. 2] Windows 7
ECHO. 3] Windows 8
ECHO. 4] Windows 8.1
ECHO.
choice /C 1234 /N /M "What version of windows?:"
if !ERRORLEVEL! EQU 1 SET IMGFILE=\v& ECHO. & SET /P ARCH=x86 or x64?: & CLS & GOTO :WinV
if !ERRORLEVEL! EQU 2 SET IMGFILE=\7& ECHO. & SET /P ARCH=x86 or x64?: & CLS & GOTO :Win7
if !ERRORLEVEL! EQU 3 SET IMGFILE=\8& ECHO. & SET /P ARCH=x86 or x64?: & CLS & GOTO :Win8
if !ERRORLEVEL! EQU 4 SET IMGFILE=\81& ECHO. & SET /P ARCH=x86 or x64?: & CLS & GOTO :Win8
:WinV
::WinVista
IF '!ARCH!'=='' GOTO MAIN
TITLE Windows Vista !ARCH!
ECHO.
ECHO. 1] Home Basic
ECHO. 2] Home Premium
ECHO. 3] Ultimate
ECHO.
choice /C 123 /N /M "What edition to install?:"
if !ERRORLEVEL! EQU 1 SET IMGINDX=2 & SET CHK= Windows Vista - Home Basic
if !ERRORLEVEL! EQU 2 SET IMGINDX=3 & SET CHK= Windows Vista - Home Premium
if !ERRORLEVEL! EQU 3 SET IMGINDX=4 & SET CHK= Windows Vista - Ultimate
GOTO :CHK
:Win7
::Win7
IF '!ARCH!'=='' GOTO MAIN
TITLE Wndows 7 !ARCH!
ECHO.
ECHO. 1] Home Basic
ECHO. 2] Home Premium
ECHO. 3] Professional
ECHO. 4] Ultimate
ECHO.
choice /C 1234 /N /M "What edition to install?:"
if !ERRORLEVEL! EQU 1 SET IMGINDX=1 & SET CHK= Windows 7 - Home Basic
if !ERRORLEVEL! EQU 2 SET IMGINDX=2 & SET CHK= Windows 7 - Home Premium
if !ERRORLEVEL! EQU 3 SET IMGINDX=3 & SET CHK= Windows 7 - Home Professional
if !ERRORLEVEL! EQU 4 SET IMGINDX=4 & SET CHK= Windows 7 - Home Ultimate
GOTO :CHK
:Win8
::Win8/1
IF '!ARCH!'=='' GOTO MAIN
TITLE Wndows 8 !ARCH! (or) 8.1 !ARCH!
ECHO.
ECHO. 1] Core
ECHO. 2] Professional
ECHO.
choice /C 12 /N /M "What edition to install?:"
if !ERRORLEVEL! EQU 1 SET IMGINDX=2 & SET CHK= Windows 8(.1) - Core
if !ERRORLEVEL! EQU 2 SET IMGINDX=1 & SET CHK= Windows 8(.1) - Professional
GOTO :CHK
:CHK
::Install OS Check
ECHO.
ECHO.You are about to start the installation of: !CHK! !ARCH!
ECHO.
choice /C YN /N /M "Continue?:"
if !ERRORLEVEL! EQU 1 GOTO :Partitioning
if !ERRORLEVEL! EQU 2 SET ARCH=&SET IMGFILE=&SET IMGINDX=& GOTO :MAIN
:Partitioning
::Partitioning Menu
choice /C MG /M "Create [M]BR or [G]PT partition table?: "
if !ERRORLEVEL! EQU 1 CLS & GOTO :MBR
if !ERRORLEVEL! EQU 2 CLS & GOTO :GPT
PAUSE & GOTO :EOF
:MBR
::Creates MBR partition for Bios/uEFI
ECHO.
DISKPART /S MBR.txt
DISM /APPLY-IMAGE /IMAGEFILE:!IMGDIR!!ARCH!!IMGFILE!!ARCH!.wim /INDEX:!IMGINDX! /APPLYDIR:W:\
ping -n 2 localhost
bcdboot W:\Windows /l EN-US
bcdboot W:\Windows /s S: /f ALL
Start CMD & EXIT
:GPT
::Creates GPT partition for uEFI
ECHO.
ECHO.Not Available.
ECHO.Use MBR or manaully create the GPT/Boot settings.
ECHO.& PAUSE & CLS & GOTO :Main
DISKPART /S GPT.txt
DISM /APPLY-IMAGE /IMAGEFILE:!IMGDIR!!ARCH!!IMGFILE!!ARCH!.wim /INDEX:!IMGINDX! /APPLYDIR:W:\
ping -n 2 localhost
bcdboot W:\Windows /l EN-US
bcdboot c:\windows /s h: /f UEFI
Start CMD & EXIT


MBR.TXT
-------------------------------------------------
select disk 0
clean
create partition primary size=300
format quick fs=ntfs label="System"
assign letter="S"
active
create partition primary
format quick fs=ntfs label="Windows"
assign letter="W"


GPT.TXT
-------------------------------------------------
select disk 0
clean
convert gpt
format quick fs=fat32 label="System"
assign letter="S"
create partition msr size=128
create partition primary
format quick fs=ntfs label="Windows"
assign letter="W"


See More: Compress Batch file code. DISM apply/diskpart

Report •

#1
December 14, 2013 at 02:28:47
For the moment, this snip cleans out some IF clutter.

This winPE stuff is of great interest to me right now.

What I need is:
A way to quickly & cleanly get to a CMD prompt, preferrably booting from a USB stick.

Hiren's boot CD runs miniXP with a RAMdisk, which is cool. But won't accress another CD or the HDD; which seems pretty lame. At best, it seems a hard way to do an easy thing.

Question of the day: How much of winXP [or 2K or win7] do we need to load to run CMD?

Stated another way, how little can we get away with?

::====== script starts here ===============
::
:: phrey89.bat 2013-12-14 16:25:06.57
@echo off & setLocal enableDELAYedeXpansioN

echo 1 XP
echo 2 Win7
choice /c:12 /n
call :!ERRORLEVEL!
goto :eof

:1
echo this is 1
goto :eof
:2
echo this is 2
goto :eof
::====== script ends here =================

=====================
M2 Golden-Triangle


Report •

#2
December 14, 2013 at 08:54:13
Well- When you've setup WindowsPE, you can have it open a CMD on statup.. There are a few ways to get to the CMD with Windows products. Like if you put in a install DVD and boot to it if you was going to format, press Shift+F10 and a command prompt is opened. Could perform the rename trick for sticky keys executable- press shift 5+ times and you've got a CMD at a nt level.

Hirens, you can open CMD and do many things I suppose. I am not sure what it is you are trying though- I have run it from CD/USB before and have no problem access another HDD like say my C: drive to perform file deletion or cleanup of a problem.

Right now, as my project as exceed normal dvd size limits, I am forced to go with USB with it. I will have WindowsPE start from usb. I have downloaded Windows 8.1 ADK which is 5.1GB total but you can limit that be deselecting the junk you do not want from the adksetup.exe file you download from Microsoft. The WindowsPE .wim file (x86) i have is around 200MB- if all you want is that then there ya go but I am adding install.wims to my project and there is where the bulk of the size comes, x86 and x64 bit versions of vista, 7, 8, and 8.1 come out to around 20GB.

I will try to work in this way of getting my IF clutter down, thanks.


Report •

#3
December 14, 2013 at 17:11:37
✔ Best Answer
Well I have made some changes and managed to make it longer lol.

Input from anyone is good, don't be shy.


CODE
~~~~~~~~~~~~~~~~~~~


:: InstallOS.CMD v0.9
:: Written by: Humphrey
::
:: Runs from Windows PE to create partitions, apply a Windows image file, and setup the boot record.
::
@ECHO OFF
::SETUP
SetLocal EnableDelayedExpansion
FOR /F "TOKENS=*" %%A IN ('TIME/T') DO SET NowT=%%A & FOR /F "TOKENS=*" %%A IN ('DATE/T') DO SET NowD=%%A
SET BIN=.\bin\
SET IMGDIR=!BIN!Images\
SET LOG=!BIN!Logs\Output.log
CD /D %~dp0
:Main
::Main Menu / OS Selection
TITLE Humphreys OS Installer
ECHO.
ECHO. Select which Windows version to install.
ECHO.
ECHO. 1] Windows Vista
ECHO. 2] Windows 7
ECHO. 3] Windows 8
ECHO.
choice /C 1234 /N /M "What version of windows?:"
SET FWD=!ERRORLEVEL!
IF !ERRORLEVEL! EQU 4 START CMD &EXIT
IF NOT !ERRORLEVEL! EQU 3 GOTO :ARCHSEL
:: Win8/1
ECHO.
ECHO. 1] Windows 8
ECHO.
ECHO. 2] Windows 8.1
ECHO.
choice /C 12 /N /M "Which to install?: "
if !ERRORLEVEL! EQU 1 SET IMGFILE=\8& SET CHK1=Windows 8&CLS
if !ERRORLEVEL! EQU 2 SET IMGFILE=\81& SET CHK1=Windows 8.1&CLS
:ARCHSEL
:: Architecture Menu
ECHO.
ECHO. 1] x32 (x86)
ECHO.
ECHO. 2] x64
ECHO.
choice /C 12 /N /M "Which architecture?:"
IF !ERRORLEVEL! EQU 1 SET Arch=x32
IF !ERRORLEVEL! EQU 2 SET Arch=x64
::Partitioning Menu
ECHO.
choice /C MG /M "Create MBR or GPT partition table?: "
if !ERRORLEVEL! EQU 1 CLS & SET PART=MBR& SET BOOT=bcdboot W:\Windows /s S: /f ALL
if !ERRORLEVEL! EQU 2 CLS & SET PART=GPT& SET BOOT=bcdboot W:\windows /s S: /f UEFI
CALL :!FWD!
:1
::WinVista
SET IMGFILE=\v
ECHO.
ECHO. Windows Vista (!ARCH!)
ECHO.
ECHO. 1] Home Basic
ECHO. 2] Home Premium
ECHO. 3] Ultimate
ECHO.
choice /C 123 /N /M "What edition to install?:"
if !ERRORLEVEL! EQU 1 SET IMGINDX=2 & SET CHK= Windows Vista Home Basic
if !ERRORLEVEL! EQU 2 SET IMGINDX=3 & SET CHK= Windows Vista Home Premium
if !ERRORLEVEL! EQU 3 SET IMGINDX=4 & SET CHK= Windows Vista Ultimate
GOTO :CHK
:2
::Win7
SET IMGFILE=\7
ECHO.
ECHO. Windows 7 (!ARCH!)
ECHO.
ECHO. 1] Home Basic
ECHO. 2] Home Premium
ECHO. 3] Professional
ECHO. 4] Ultimate
ECHO.
choice /C 1234 /N /M "What edition to install?:"
if !ERRORLEVEL! EQU 1 SET IMGINDX=1 & SET CHK= Windows 7 Home Basic
if !ERRORLEVEL! EQU 2 SET IMGINDX=2 & SET CHK= Windows 7 Home Premium
if !ERRORLEVEL! EQU 3 SET IMGINDX=3 & SET CHK= Windows 7 Home Professional
if !ERRORLEVEL! EQU 4 SET IMGINDX=4 & SET CHK= Windows 7 Ultimate
GOTO :CHK
:3
ECHO.
ECHO. !CHK1! (!ARCH!)
ECHO.
ECHO. 1] Core
ECHO.
ECHO. 2] Professional
ECHO.
choice /C 12 /N /M "What edition to install?:"
if !ERRORLEVEL! EQU 1 SET IMGINDX=2 & SET CHK= Core&CLS
if !ERRORLEVEL! EQU 2 SET IMGINDX=1 & SET CHK= Professional&CLS
GOTO :CHK
:CHK
::Install OS Check
TITLE Install Check
ECHO.
ECHO.Start installation of: !CHK1!!CHK! (!ARCH!)
ECHO.
choice /C YN /M "Continue"
if !ERRORLEVEL! EQU 1 CLS & GOTO :APPLYSETTINGS
if !ERRORLEVEL! EQU 2 SET ARCH=&SET IMGFILE=&SET IMGINDX=& CLS & GOTO :MAIN
:APPLYSETTINGS
:: Applies image file and creates the partitions tables and boot settings.
ECHO.
DISKPART /S !BIN!!PART!.txt
DISM /APPLY-IMAGE /IMAGEFILE:!IMGDIR!!ARCH!!IMGFILE!!ARCH!.wim /INDEX:!IMGINDX! /APPLYDIR:W:\
ping -n 2 localhost
bcdboot W:\Windows /l EN-US
!BOOT!
:LOG
:: Outputs log of completed install.
ECHO.Installed !CHK1!!CHK! !ARCH! on !NowD! @ !NowT!!LOG!
Start CMD & EXIT

message edited by Phrey89


Report •

Related Solutions

#4
December 15, 2013 at 01:56:22
Thanks for the feedback. shift+f10 didn't work with 2K or XP, but these are kimchi versions.

=====================
M2 Golden-Triangle


Report •

#5
December 16, 2013 at 21:19:32
I doubt that command works with anything older than Windows Vista.

Report •

Ask Question