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

Disk preparation Batch (.cmd) script for winntsetup
« on: January 20, 2016, 02:52:49 AM »

Venerence

  • Jr. Chef
  • **
  • Date Registered: Jan 2014
  • Posts: 54
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 20, 2016, 06:20:25 AM by Lancelot »

Re: Disk preparation Batch (.cmd) script for winntsetup
« Reply #1 on: January 26, 2016, 04:16:40 AM »

Venerence

  • Jr. Chef
  • **
  • Date Registered: Jan 2014
  • Posts: 54
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 26, 2016, 04:16:59 AM by Venerence »

Re: Disk preparation Batch (.cmd) script for winntsetup
« Reply #2 on: January 26, 2016, 09:24:12 AM »

Lancelot

  • Gena Baker
  • Grand Chef
  • *****
  • Date Registered: Sep 2010
  • Posts: 10350
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 26, 2016, 09:41:48 AM »

was_JFX

  • Code Baker
  • Grand Chef
  • *****
  • Date Registered: Dec 2010
  • Posts: 1074
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 26, 2016, 09:43:25 AM by JFX »

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

Venerence

  • Jr. Chef
  • **
  • Date Registered: Jan 2014
  • Posts: 54
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, 11:43:20 PM by Venerence »

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

Venerence

  • Jr. Chef
  • **
  • Date Registered: Jan 2014
  • Posts: 54
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 10, 2016, 07:09:40 AM by Venerence »

Re: Disk preparation Batch (.cmd) script for winntsetup
« Reply #6 on: November 22, 2018, 10:23:58 AM »

Oakim

  • Apprentice
  • *
  • Date Registered: Nov 2018
  • Posts: 2
Hi.

Don't know if you will get this or not :)

If you do is there anyway you can implement .esd to you program?

Re: Disk preparation Batch (.cmd) script for winntsetup
« Reply #7 on: November 22, 2018, 11:11:59 AM »

Oakim

  • Apprentice
  • *
  • Date Registered: Nov 2018
  • Posts: 2
I found this newbielink:http://www.alexcomputerbubble.com/diskpart-gui-update/ [nonactive]

This is a very simple GUI for Diskpart that makes a disk preparation very simple before using WinNTSetup3.

Re: Disk preparation Batch (.cmd) script for winntsetup
« Reply #8 on: November 22, 2018, 01:51:24 PM »

bob.omb

  • Code Baker
  • Grand Chef
  • *****
  • Location: USA
  • Date Registered: Jul 2017
  • Posts: 1261
I had not seen this before...   :wink:  I just drop this folder into WinNTSetup folder... http://theoven.org/index.php?topic=1236.msg27065#msg27065 Then run the shortcut inside.  It does the same as his batch but also launches WinNTSetup and inputs the drive letters for you.  Then you only have to pick your ISO and edition...  I prefer running one program that is as simple as possible but am too lazy to write a proper wrapper...  Its a shame because as simple as this was it looked good, I'd love for the dev to come back and add that to his exe, it is even possible to launch WinNTSetup from cmd line and make a very clean process for the end user...

There are 4 lines of txtreplace using powershell in that batch, seems to work fine in PE with current powershell plugins, they could easily be replaced with cmd style txtreplace (probably would work faster that way anyway)

- Its just food for thought, but it really seems unnecessary to open and close a program then open WinNTSetup after, just chain them together at the least otherwise its too bulky...  Best option would be creating something that uses WinNTSetups functionality with cmd (A complete GUI Wrapper)
« Last Edit: November 22, 2018, 01:58:12 PM by bob.omb »

 

Powered by EzPortal