Topic: Disk preparation Batch (.cmd) script for winntsetup  (Read 1447 times)

0 Members and 1 Guest are viewing this topic.

Disk preparation Batch (.cmd) script for winntsetup
« on: January 19, 2016, 04:52:49 PM »

Venerence

  • Jr. Chef
  • **
  • Date Registered: Jan 2014
  • Posts: 46
To make things a bit more user friendly, I have created a short cmd to prepare a drive for a windows installation. This comes with (several) caveats:

1) It's been working for me, but still needs more testing. Do *not* have anything you want to keep the data for plugged in when trying the script, just in case

2) It erases the whole drive selected, *including* any extra partitions (like recovery or data partitions). If you want to prepare a drive with partitions you want to keep, just format the partitions the old fashioned way

3) This is a script designed to erase a drive. See 1, do not keep anything with data you care about plugged in, seriously.

I've put in some input sanitation in there, but it's probably still sloppy enough to make a real programmer cry. Feel free to improve as people see fit.

Code: [Select]
pushd ~%dp0
echo off
:begin
cls
echo Are you formatting UEFI or MBR?
echo =============
echo.
echo 1) UEFI
echo 2) MBR
echo.
set /p op=Type option:
if "%op%"=="1" goto op1
if "%op%"=="2" goto op1

echo did not recognize input
pause
exit

:op1
cls
echo.
echo.
echo =============
wmic diskdrive get model,deviceid,serialnumber
echo =============
echo.
echo choose which numbered disk to erase (0, 1, 2, etc.)
set /p op2=Type single number only:
if "%op2%"=="" goto op1

cls
echo.
echo.
echo =============
wmic diskdrive get model,deviceid,serialnumber | findstr PHYSICALDRIVE%op2%
echo =============
if %ERRORLEVEL% EQU 1 echo Not a recognized drive, exiting...
if %ERRORLEVEL% EQU 1 pause
if %ERRORLEVEL% EQU 1 exit
echo.
echo Are you sure you want to erase EVERYTHING, including ALL PARTITIONS on this drive?
echo type DELETE in all caps to confirm
set /p op3=Confirm Erase:

if "%op3%"=="DELETE" goto op3
echo no confirmation, exiting...
pause
exit

:op3
if "%op%"=="1" goto uefirun
if "%op%"=="2" goto mbrrun

:mbrrun
@echo select disk %op2% > mbr-diskpart.txt
@echo clean>> mbr-diskpart.txt
@echo create partition primary>> mbr-diskpart.txt
@echo format quick fs=ntfs label="Windows">> mbr-diskpart.txt
@echo assign letter="O">> mbr-diskpart.txt
@echo active>> mbr-diskpart.txt
@echo exit>> mbr-diskpart.txt
diskpart /s mbr-diskpart.txt
echo done, you can now use winntsetup3 to install windows. Boot ^& Install letter is ^<O^>
pause
exit

:uefirun
@echo select disk %op2% > uefi-diskpart.txt
@echo clean>> uefi-diskpart.txt
@echo convert gpt>> uefi-diskpart.txt
@echo create partition efi size=300>> uefi-diskpart.txt
@echo format quick fs=fat32 label="System">> uefi-diskpart.txt
@echo assign letter="N">> uefi-diskpart.txt
@echo create partition msr size=128>> uefi-diskpart.txt
@echo create partition primary>> uefi-diskpart.txt
@echo format quick fs=ntfs label="Windows">> uefi-diskpart.txt
@echo assign letter="O">> uefi-diskpart.txt
@echo exit>> uefi-diskpart.txt
diskpart /s uefi-diskpart.txt
echo done, you can now use winntsetup3 to install windows. Boot letter is ^<N^>, Install Drive is ^<O^>
pause
exit
« Last Edit: January 19, 2016, 08:20:25 PM by Lancelot »

Re: Disk preparation Batch (.cmd) script for winntsetup
« Reply #1 on: January 25, 2016, 06:16:40 PM »

Venerence

  • Jr. Chef
  • **
  • Date Registered: Jan 2014
  • Posts: 46
I've tested the script on several computers so far via win10se, and no unintended consequences (erased wrong drive, set computer on fire, etc.) so far. If someone else wants to develop it into a plugin, they're more then welcome to copy and paste any of the script into one, I just have very little experience with plugin maintenance.
« Last Edit: January 25, 2016, 06:16:59 PM by Venerence »

Re: Disk preparation Batch (.cmd) script for winntsetup
« Reply #2 on: January 25, 2016, 11:24:12 PM »

Lancelot

  • Gena Baker
  • Grand Chef
  • *****
  • Date Registered: Sep 2010
  • Posts: 6742
Thanks for update.

I just have very little experience with plugin maintenance.
Use
Utils\PC Packed (Plugin Creator Packed)
1) reformat-windows.cmd
2) reformat-windows.cmd
3) Gooo
It will work out of box on all projects around TheOven.org  :thumbsup:

:turtle:

Re: Disk preparation Batch (.cmd) script for winntsetup
« Reply #3 on: January 25, 2016, 11:41:48 PM »

JFX

  • Code Baker
  • Sr. Chef
  • ****
  • Date Registered: Dec 2010
  • Posts: 808
Well you should really checks the diskpart return code.

Code: [Select]
@echo off

rem cause an error, by wrong type
> diskpart.txt echo list disks
>>diskpart.txt echo exit
diskpart /s diskpart.txt
IF %Errorlevel%==0 (
 echo.
 echo done, you can now use winntsetup3 to install windows. Boot letter is ^<N^>, Install Drive is ^<O^>
 echo.
 pause
) else (
 echo.
 echo Diskpart had a problem! Exitcode: %Errorlevel%
 echo.
 pause
)
« Last Edit: January 25, 2016, 11:43:25 PM by JFX »

Re: Disk preparation Batch (.cmd) script for winntsetup
« Reply #4 on: May 09, 2016, 04:10:46 AM »

Venerence

  • Jr. Chef
  • **
  • Date Registered: Jan 2014
  • Posts: 46
I've gone ahead and spent the time to flesh this out, as trying to get my colleagues to adopt anything that is slightly harder then the windows built in setup is nearly impossible. So here it is, as a standalone portable exe (32 and 64 bit PE versions, does all nt6 flavours of windows regardless of PE environment), gui and all.

So Here is winmage 1.0, an executable I built out of Wizard's Apprentice and battoexe.

Think of it as winntsetup lite, far less options, and far simpler. You choose the drive, you choose your wim file (it should autodetect it if it's in a standard spot), you choose the edition, you hit go. Restart and you're in windows.

I've also added in some basic error checking as per JFX's advice, still nothing fancy, but at least it'll give you an idea at what step it failed at.

Give it a go! tested in 10se 32 and 64 bit. Let me know of any bugs.
« Last Edit: May 22, 2016, 01:43:20 PM by Venerence »

Re: Disk preparation Batch (.cmd) script for winntsetup
« Reply #5 on: May 09, 2016, 09:07:47 PM »

Venerence

  • Jr. Chef
  • **
  • Date Registered: Jan 2014
  • Posts: 46
Already a couple things fixed, here's 1.01

Encountered Issues:
dialogue box would lose focus when moving between options
MBR mode would not install correctly if booting from a UEFI PE environment
UEFI mode would not install correctly if booting from a MBR PE environment

Fixes:
Enabled background CMD window as dialogues had focus issues when hiding it, also now shows DISM status
windows now installs correctly, regardless of architecture or type of PE environment currently loaded (assuming the computer supports it)

Other note: since this is a wrapper for a batch script, antivirus will almost always flag it. There's no around it for this kind of scripting, short of just keeping it as a batch script instead of an executable.
Other note 2: both 32 and 64 bit versions can be run from a regular windows install as well, doesn't have to be a PE environment (unless you're installing to the boot drive obviously). IE: you can plug in an extra temporary drive, format and install to that, plug that drive into another computer (or change your boot order) and it should continue the install process like normal.
« Last Edit: May 09, 2016, 09:09:40 PM by Venerence »

 

Powered by EzPortal