Link to home
Start Free TrialLog in
Avatar of LearningCpp
LearningCpp

asked on

how can i make a bootable usb drive programatically

Hi experts,
I need to make a usb drive bootable using a tool, I am asking this question here as i cannot use any third party tool to do this and i need to implement this in my code in C++.
The req are: user will insert an external USB hard disk on the machine.
and when he clicks "make bootable", the tool will first format the usb disk, I will be using format.exe to format the disk, I already have the boot files ready with me (ntldr, bootfix etc with me).
If i only copy these files to the usb disk, i will not be able to boot from this usb disk because:
The MBR on the disk is not present.
So with c++ how can i write the MBR on the USB hard drive so that it will point it to the boot files on the same disk so that my USB hard disk becomes bootable.

I am sure there is a way, but i am unaware what is it.
TIA
Avatar of Anthony2000
Anthony2000
Flag of United States of America image

Avatar of jkr
Use 'SHFormatDrive()' (http://msdn.microsoft.com/en-us/library/bb762169(VS.85).aspx) and set the following option:

SHFMT_OPT_SYSONLY
0x002. Selects the Create an MS-DOS startup disk option, creating a system boot disk.
I didn't check that you are doing this under Windows. But the SHFormatDrive still requires some user interaction:
from SHFormatDrive's remarks section:
"The format is controlled by the dialog interface. That is, the user must click the OK button to actually begin the formatthe format cannot be started programmatically."


Avatar of LearningCpp
LearningCpp

ASKER

No user interaction required, so i cannot user SHFormatDrive()?
Here is a link that discusses using BartPE: http://www.dedoimedo.com/computers/livecd.html See the section titled:  

"Bootable USB sticks"

create autorun.inf in your home directory of USB memory disk that include these texts:
[autorun]
OPEN=SETUP.EXE
ICON=SETUP.EXE,0

as you know, you can change setup.exe and setup.ico as you desire
regards...
ASKER CERTIFIED SOLUTION
Avatar of LearningCpp
LearningCpp

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial