Tip: Set the options in RMPrepUSB, untick the 'No user prompts' box and click '6 Prepare Drive' - the RMPartUSB parameters will be displayed before they are executed and you can see the parameters that will be used. RMPrepUSB also has an 'Info box' - just hover over an option to see what it does.
To understand the RMPartUSB options better, read the RMPrepUSB User Guide.

Q1. How can I use RMPartUSB in my Windows script files (e.g. .cmd or .bat files)?

A1. Most functions of RMPrepUSB are available in RMPartUSB and so can be scripted - except you will need to use XCOPY to copy files to the USB drive once it has been formatted.

Some special commands and code examples are shown below (code in bold, keywords in red bold):

RMPARTUSB LIST

RMPARTUSB v2.1.600 (c)2008-10 RM Education plc [SSi]

====================================================

*DRIVE 1 - 7.5GiB TakeMS MEM-Drive Smart USB Devi Fw=0.00 H:

DRIVE 2 - 7.5GiB Verbatim STORE N GO USB Device Fw=5.00 J:

RMPARTUSB LIST ALLDRIVES

RMPARTUSB v2.1.600 (c)2008-10 RM Education plc [SSi]

====================================================

*DRIVE 0 - 232.8GiB ST3250820AS ATA Device Fw=3.ADG Sno=202020202020202 C:

DRIVE 1 - 7.5GiB TakeMS MEM-Drive Smart USB Devi Fw=0.00 H:

DRIVE 2 - 7.5GiB Verbatim STORE N GO USB Device Fw=5.00 J:

RMPARTUSB FIND > drv.cmd

example drv.cmd file produced is:

SET DRIVE=1

SET DRIVEDESC=TakeMS MEM-Drive Smart USB Device

SET DRIVESIZE=8086618112

SET DRIVELETTER=H:

SET DRIVE1DESC=TakeMS MEM-Drive Smart USB Device

SET DRIVE1SIZE=8086618112

SET DRIVE1LETTER=H:

SET DRIVE2DESC=Verbatim STORE N GO USB Device

SET DRIVE2SIZE=8011120640

SET DRIVE2LETTER=J:

SET DRIVE3DESC=0

SET DRIVE3SIZE=15800762880

SET DRIVE3LETTER=G:

SET DRIVE4DESC=0

SET DRIVE4SIZE=1998743040

SET DRIVE4LETTER=I:

SET DRIVE5DESC=0

...

etc. etc. up to DRIVE26xxxx

(Note: DRIVE, DRIVEDESC and DRIVELETTER are used for the FIRST USB DRIVE to be found, if more than one USB drive is expected to be in the system then use the DRIVEn variables).

Example of how to use in a batch file:

RMPartUSB FIND > drv.cmdcall drv.cmddel drv.cmdecho Drive 1 is a %DRIVE1DESC% with a size of %DRIVE1SIZE% and a volume letter of %DRIVE1LETTER%

Or an alternative that does the same thing without needing a temporary file:

FOR /F "tokens=*" %%A IN ('RMPartUSB FIND') DO %%A
echo Drive 1 is a %DRIVE1DESC% with a size of %DRIVE1SIZE% and a volume letter of %DRIVE1LETTER%

Or detect if a single USB drive is present and get it's drive number

@echo offsetlocal enabledelayedexpansion"C:\Program Files (x86)\RMPrepUSB"\RMPartUSB FIND > drv.cmdset DRIVE=call drv.cmd > nuldel drv.cmdif "%DRIVE%"=="" echo NO USB DRIVE FOUND! & pause & goto :eofset NXT=%DRIVE%:ffset /a NXT=%NXT%+1if "%NXT%"=="27" goto :ggset S=!DRIVE%NXT%SIZE!if not "%S%"=="0" goto :ggif "%S%"=="0" goto :ff:ggsetlocal disabledelayedexpansionif NOT "%S%"=="0" echo MORE THAN ONE USB DRIVE FOUND! & pause & goto :eofecho USB DRIVE %DRIVE% CONNECTED

Another example - ask user to select a USB drive, wipe and format it and copy files to it:

RMPARTUSB LISTset /P DD=Please enter the USB Flash drive number you want to use: rmpartusb DRIVE=%dd% WINPE FAT32 2PTN VOLUME=WINPEif errorlevel 1 echo COMMAND FAILED!if errorlevel 1 goto :EOFrmpartusb DRIVE=%dd% GETDRV > drv1.cmdset USBDRIVELETTER=call drv1.cmddel drv1.cmdIf "%USBDRIVELETTER%"="" goto :EOFxcopy /herky C:\mysourcefiles\*.* %USBDRIVELETTER%\*.*echo all files copied!

example drv1.cmd file produced is:

SET USBDRIVE=1

SET USBDRIVEDESC=TakeMS MEM-Drive Smart USB Device

SET USBDRIVESIZE=8086618112

SET USBDRIVELETTER=H:

Tip: add SURE before the WINPE parameter if you don't want to ask the user if he is sure he wants to wipe the drive (don't add SURE to the end after VOLUME as it won't work!)

If testing for drive sizes using Windows command shell, maximum number is +/- 1TB (31 bits).

You can reduce the number returned to MB units using

set USBDRIVESIZE=%USBDRIVESIZE:~0,-6%

this will chop off the last 6 digits. You can then test the size using

if "%USBDRIVESIZE%"=="" echo ERROR!

if %USBDRIVESIZE% LSS 137400 echo Drive is below 137GB

Another example - ask user to select the USB drive, partition and format the drive, add grub4dos and copy files to it:

@echo offREM change to our working folderpushd "C:\Program Files (x86)\RMPrepUSB"REM list all USB drives so user can see them and their drive numberRMPARTUSB LISTREM Ask user for a drive numberset /P DD=Please enter the USB Flash drive number you want to use: REM execute RMPARTUSB (insert SURE if you don't want the user prompt)RMPARTUSB DRIVE=%dd% MSDOS FAT32 2PTN FORCELBA VOLUME=WINPEif errorlevel 1 echo RMPARTUSB COMMAND FAILED!if errorlevel 1 goto :EOFset USBDRIVELETTER=REM get the drive letter of the newly formatted driveFOR /F "tokens=*" %%A IN ('RMPARTUSB DRIVE^=%dd% GETDRV') DO %%AIf "%USBDRIVELETTER%"=="" goto :EOFREM install grub4dosgrubinst -v --skip-mbr-test (hd%dd%)If errorlevel 1 goto :EOFREM use touchdrv to ensure MBR changes are not removed by Windows!touchdrv %USBDRIVELETTER%REM copy grldr file over which is needed by grub4doscopy grldr %USBDRIVELETTER%If errorlevel 1 goto :EOFREM copy over boot files (assumes a menu.lst file has been added for use by grub4dos)xcopy /herky .\mybootfiles\*.* %USBDRIVELETTER%\*.*If errorlevel 1 goto :EOFecho Finished - All files copied!

How to find the drive number for a given drive letter

Place the following text in a file called getdnum.cmd

@echo offecho.SET FIND=%1IF "%FIND%"=="" echo ERROR - Usage: %0 [driveletter]: (e.g. %0 H:) && goto :EOFSET FIND=%FIND:~0,1%SET FIND=%FIND%:FOR /F "tokens=*" %%A IN ('RMPartUSB FIND') DO %%AREM FOR /F "tokens=*" %%A IN ('RMPartUSB FIND ALLDRIVES') DO %%ASET DRIVENUM=SET DRIVESIZE=if /i "%DRIVE1LETTER%"=="%FIND%" SET DRIVENUM=1 && SET DRIVESIZE=%DRIVE1SIZE%if /i "%DRIVE2LETTER%"=="%FIND%" SET DRIVENUM=2 && SET DRIVESIZE=%DRIVE2SIZE%if /i "%DRIVE3LETTER%"=="%FIND%" SET DRIVENUM=3 && SET DRIVESIZE=%DRIVE3SIZE%if /i "%DRIVE4LETTER%"=="%FIND%" SET DRIVENUM=4 && SET DRIVESIZE=%DRIVE4SIZE%if /i "%DRIVE5LETTER%"=="%FIND%" SET DRIVENUM=5 && SET DRIVESIZE=%DRIVE5SIZE%if "%DRIVENUM%"=="" echo DRIVE NUMBER FOR %FIND% NOT FOUND! && goto :EOFecho %FIND% is Drive %DRIVENUM% Size=%DRIVESIZE%

You can use this by calling (for example) getdnum.cmd h or getdnum.cmd H: , the variable DRIVENUM will contain the physical drive number of the USB drive or be empty if it is not found. Add the ALLDRIVES parameter to the RMPartUSB FIND command if you want all drives to be listed and not just USB drives (remove the word REM from the grey line so that it will run and then add the word REM to the beginning of green the line just above it).

Example using only Diskpart (not for XP)

Call as .cmd file with drive letter as parameter - e.g. call GetDnum.cmd L:

@ECHO OFF SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION IF "%1."=="." ECHO Missing Parameter&GOTO :EOF SET MyVol=%1 SET MyDisk= FOR /F "delims=" %%A IN (' ^( ECHO Select Volume %MyVol%^&ECHO list disk ^)^|diskpart^|FIND "* " ') DO SET Mydisk=%%A IF NOT DEFINED Mydisk ECHO ERROR: NO DISK NUMBER FOUND&GOTO :EOF FOR /F "tokens=1 delims=0123456789" %%A IN ("%MyDisk%") DO SET /A Mydisk=!Mydisk:%%A=! 2>nul ECHO %MyVol%: is on DISK %MyDisk%

Find the drive number of the drive containing the batch file FindMe.cmd (RMPartUSB must be in same folder or in the %path% variable)

Place FindMe.cmd on the USB flash drive and RMPartUSB.com. Admin rights required.

FindMe.cmd

@echo offsetlocal enabledelayedexpansionFOR /F "tokens=*" %%A IN ('RMPartUSB FIND') DO %%AFor /L %%a in (1,1,26) do ( IF [%~d0]==[!DRIVE%%aLETTER!] ( Echo %%a is a match Set MyDrive=%%a Goto :EOF ))

The variable MyDrive will contain the USB drive number.

Thanks to D.Roberts for this code!

For a way to find the drive number without using RMPartUSB (under a full Windows OS, not WinPE) - see here.

Place SwitchMe.cmd on the USB drive (below) + RMPartUSB.exe - when SwitchMe.cmd is run, it will switch a Removable Flash drive's partition 2 with partition 1, to make partition 2 accessible to Windows.

Run it again and it will swap back the partitions.

Admin rights required.

SwitchMe.cmd

@echo offsetlocal enabledelayedexpansionFOR /F "tokens=*" %%A IN ('RMPartUSB FIND') DO %%AFor /L %%a in (1,1,26) do ( IF [%~d0]==[!DRIVE%%aLETTER!] ( Echo %%a is a match rmpartusb.exe drive=%%a Firstpart=2 sure Goto :EOF ))

Thanks to D.Roberts for this code!

Q2 How can I determine the correct command for RMPartUSB?

    • Type RMPartUSB for command line usage. Typing RMPARTUSB on the command line should give some help.
    • Read the manual.
    • Use RMPrepUSB, set your options and click the Prepare Drive button and note down the command line that it uses to call RMPartUSB (uncheck 'No user prompts' checkbox).

Q3. How can I modify bytes of a sector (or sectors) under Windows (e.g. MBR) ?

You can use USBTOFILE to save any sector or group of sectors to a file.

Then you can modify the file using dd.exe for Windows

e.g. to remove the 3rd partition table entry, use:

dd bs=1c count=16 seek=478 skip=478 if=/dev/zero of=C:\temp\test.bin

You can then write back the file using RMPartUSB FILETOUSB.

To change certain bytes to certain values, try setbytes

For a native 64-bit MBR utility (and 32-bit version) try mbrFix.exe and mbrFix64.exe

Other snippets

Get drive letter of partition with Volume label of "E2B"

Not case sensitive as /i used

@echo offset myDrive=for %%a in (a b c d e f g h i j k l m n o p q r s t u v w x y z) do vol %%a: 2>nul | find /i "E2B" >nul && set myDrive=%%a:if "%myDrive%"=="" (echo Cannot find volume) else (echo Drive letter is %myDrive%))

Here are some Diskpart scripts - they do not rely on 3rd party utility - work on 64-bit or 32-bit WinPE

Count number of Removable Drives (Win7 or later only)

Assumes English language

:CountRem@echo offset myDrive=set CNT=0For /L %%a in (1,1,26) do ((echo sel disk %%a & echo det disk ) | diskpart.exe | find.exe "Removable" >nul && echo %%a IS REMOVABLE DISK && Set myDrive=%%a && set /A CNT=CNT+1 > nul )echo %CNT% Removable drives foundgoto :EOF

If only one Removable drive then myDrive has it's drive number

Get first Removable disk in system

Assumes English language

:GetRem@echo offset myDrive=For /L %%a in (1,1,26) do ((echo sel disk %%a & echo det disk ) | diskpart.exe | find.exe "Removable" >nul && set myDrive=%%a && goto :EOF )goto :EOF

Get size of a USB drive:

in a batch file where DD is the drive number...

for /f "delims== tokens=2" %%s in ('rmpartusb "DRIVE=%DD% GETDRV" ^| FIND "SIZE"') do set DSZ=%%s


Report abuse

privacy policy