**Need help with Diskpart in batch file to make USB bootable

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
GeekyGuyJax
Posts: 4
Joined: 21 Sep 2009 14:56

**Need help with Diskpart in batch file to make USB bootable

#1 Post by GeekyGuyJax » 21 Sep 2009 16:59

Hi Guys,

I have created the below .cmd file to format my USB flash drive but now
I want to add additional script to make it bootable any ideas ?
I know i can use DiskPart with a text file to do it manually but I would rather
have it in a all-in-one script..

This is what I have so far...

@ECHO OFF

cls && Color 1E
Echo Geeks Computer Services August 2009. All rights reserved.
echo.
echo.
echo +=================================================+
echo + This file will Reformat your USB flash drive! +
echo +=================================================+
:start
echo.
echo Enter your USB flash drive letter (D,E,F,G,H,I,J,K,L,M,N) then press Enter
set /p drive=
if ‘%drive%’ == ‘D’ goto proceed
if ‘%drive%’ == ‘E’ goto proceed
if ‘%drive%’ == ‘F’ goto proceed
if ‘%drive%’ == ‘G’ goto proceed
if ‘%drive%’ == ‘H’ goto proceed
if ‘%drive%’ == ‘I’ goto proceed
if ‘%drive%’ == ‘J’ goto proceed
if ‘%drive%’ == ‘K’ goto proceed
if ‘%drive%’ == ‘d’ goto proceed
if ‘%drive%’ == ‘e’ goto proceed
if ‘%drive%’ == ‘f’ goto proceed
if ‘%drive%’ == ‘g’ goto proceed
if ‘%drive%’ == ‘h’ goto proceed
if ‘%drive%’ == ‘i’ goto proceed
if ‘%drive%’ == ‘j’ goto proceed
if ‘%drive%’ == ‘k’ goto proceed
if ‘%drive%’ == ‘l’ goto proceed
if ‘%drive%’ == ‘m’ goto proceed
if ‘%drive%’ == ‘n’ goto proceed
cls
goto error

:error
echo.
echo The drive letter you entered was not recognized
echo.
pause
cls
goto start

:proceed
cls
echo.
echo Would you like to format flash drive %drive%:?
echo.
echo Type Y for Yes or N for NO then press Enter
set /p ok=
if ‘%ok%’ == ‘y’ goto yes
if ‘%ok%’ == ‘Y’ goto yes
if ‘%ok%’ == ‘n’ goto no
if ‘%ok%’ == ‘N’ goto no
cls

:yes
cls
echo Pre-Stage Format:
echo First, let's ensure that the flash drive is inserted
echo.
format %drive%: /FS:fat32 /Q


END

BILL Dos
Posts: 12
Joined: 22 Sep 2009 11:49
Location: USA

** Tested and Working **

#2 Post by BILL Dos » 23 Sep 2009 06:30

Insert thumb drive go to run box or command line and type in diskmgmt.msc and jot down disk# and usb drive letter.
open up txt file and input disk# on the Select Disk option and drive letter on the Assign Letter option.
Use the example below for your script file (In this exampple I used Disk 2 and F drive letter for the USB flash drive)

Select Disk 2
Clean
Create Partition Primary
Select Partition 1
Active
Format FS=Fat32
Assign letter=F noerr
END

Save as Script.txt then create folder on desktop call it DiskPart and place Script.txt in the folder.
Now create a batch file call it diskpart and use the below code then save as diskpart.bat and also save in folder.
Insert your XP or Vista Install disk, Insert your UsB flash drive and then click on the batch file to do it's magic!
Note: used D as CD-ROM letter, change if your drive is different, also in order for all of this to work the script.txt
and diskpart.bat MUST be in same folder!



@ECHO OFF

cls && Color 1E
ECHO Date and Start Time: %DATE% %TIME:~0,8%
echo.
echo.
echo +=============================+
echo + Creating a bootable USB flash drive! +
echo +=============================+

rem using script.txt file to partition and format usb flash drive
DiskPart.exe /s Script.txt

rem copy files off of cd-rom/dvd over to usb flash drive
XCOPY d:\*.* f:\ /s/e/h/f
echo.
echo.
echo +========================================+
echo + You can now install Vista from your USB Drive! +
echo + Don't forget to set USB drive as the first boot device in bios. +
echo +========================================+
pause

EXIT

Post Reply