Jump to content

Install Windows 10 from a USB key with a batch file


Recommended Posts

On 7/18/2020 at 11:06 AM, jaclaz said:

Post one or two of the .txt diskpart script.

JFYI, later (i.e. once the diskpart scripts/commands are tested and work) it is possible to embed them within the batch.

See:

https://msfn.org/board/topic/126069-updated-on-feb-27-2011-ordering-messed-drive-letter-batch-file/page/2/?tab=comments#comment-817142

https://msfn.org/board/topic/126069-updated-on-feb-27-2011-ordering-messed-drive-letter-batch-file/page/2/?tab=comments#comment-817388

You need "better" control of the input, if the user by mistake inputs "strange" characters there may be issues, though it is possible to better validate set /p input, In windows post-XP there is (in case) the choice command which accepts input without needing the [ENTER], maybe it would be more suited than set /p (as it has - besides input validation - also a timeout and a default provision):
https://ss64.com/nt/choice.html

jaclaz

P,S, : ONLY for the fun of it, this is how I would have written your batch (mind you everyone has his/her own "style", not necessarily one is better than the other):


@ECHO OFF
SETLOCAL

:debut
CLS
SET my_120GB=1 120 GB c:/Project/120.txt
SET my_200GB=2 200 GB x:/diskpart/200.txt
SET my_450GB=3 450 GB x:/diskpart/450.txt
SET my_1000GB=4 1000 GB x:/diskpart/1000.txt
SET my_2000GB=5 2000 GB x:/diskpart/2000.txt

ECHO *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
ECHO "DISK CAPACITY AVAILABLE"
ECHO *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
ECHO.
ECHO 1^)  120 GB
ECHO 2^)  200 GB
ECHO 3^)  450 GB
ECHO 4^) 1000 GB
ECHO 5^) 2000 GB
ECHO.
ECHO *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
Choice /T 60 /D 1 /C 12345 /M "Choose your disk:"
ECHO *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

CALL :MyChoice %Errorlevel%

ECHO DONE.
PAUSE
:fin

GOTO :EOF

:MyChoice
FOR /F "tokens=2,3,4 delims= " %%A IN ('SET my_ ^|FIND "GB=%1"') DO (
ECHO.
ECHO "you have chosen: %%A %%B"
ECHO diskpart /s %%C
)
GOTO :EOF

 

Hi Sir,

Thanks for the code.
I tested in my computer it works very well.
But as you I have to test it on VMWare.
So is there any chance to do it in VMWare?
In my opinion I think I should use list disk for displaying all the disk in VMWare, after displaying the disks I have to use diskpart command.
I have a few problem to solve Checking the script in VMware, use the list disk command and the action of Diskpart.

 

Link to comment
Share on other sites


VmWare (running the same OS) won't make any difference from the "real" machines, so that is not a problem.

But most probably you missed this:

unless the actual diskpart scripts for partitoning/formatting are different for each disk size there is no need to "choose" a size.

Commanding diskpart from batches is not straightforward, but it is also not particularly complicated/complex, though for querying the disk data maybe WMI/WMIC would be more appropriate/easier.

As always you need to test commands on command line and then create the corresponding sequence of commands.

Examples (to get the size of disks):
On command line:

Diskpart
list disk

Or using WMIC:
WMIC Path Win32_DiskDrive Get Index,Model,Size

In batch:

@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION

::Disksizes with diskpart
::The exact number of lines to skip needs to be checked as it may depend on OS and language
ECHO By Diskpart
FOR /F "skip=8 tokens=1,2,4,5 delims= " %%A IN ('ECHO list disk^|diskpart.exe^|FIND /V "DISKPART"') DO SET my_%%A_%%B=%%C %%D
SET my_
ECHO.

::Let's reset variables
FOR /F "tokens=1 delims==" %%A IN ('SET my_') DO SET %%A=

ECHO By WMIC

FOR /F "tokens=2,3,4,5,6 delims=," %%A IN ('WMIC Path Win32_DiskDrive Get Index^,Model^,Size^,Status^,SystemName /format:csv^|FIND /V "Index"') DO (
IF "%%D"=="OK" SET my_disk_%%A_Model=%%B&SET my_disk_%%A_Size=%%C
IF DEFINED my_disk_%%A_Size SET /A my_disk_%%A_Size_GB=!my_disk_%%A_Size:~0,-6!/1074 
)
SET my_

 

jaclaz

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...