Solved

how can i make a bootable usb drive programatically

Posted on 2008-09-29
7
1,318 Views
Last Modified: 2013-11-14
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
0
Comment
Question by:LearningCpp
7 Comments
 
LVL 8

Expert Comment

by:Anthony2000
ID: 22598802
0
 
LVL 86

Expert Comment

by:jkr
ID: 22598824
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.
0
 
LVL 8

Expert Comment

by:Anthony2000
ID: 22598966
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."


0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:LearningCpp
ID: 22599504
No user interaction required, so i cannot user SHFormatDrive()?
0
 
LVL 8

Expert Comment

by:Anthony2000
ID: 22600115
Here is a link that discusses using BartPE: http://www.dedoimedo.com/computers/livecd.html See the section titled:  

"Bootable USB sticks"

0
 
LVL 17

Expert Comment

by:CSecurity
ID: 22605166
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...
0
 

Accepted Solution

by:
LearningCpp earned 0 total points
ID: 22707491
Can i use IOCTL_DISK_SET_PARTITION_INFO and PARTITION_INFORMATION_MBR in some way to do this?

Cannot use BartPE.

which setup.exe will use autorun.inf?
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

This is a little timesaver I have been using for setting up Microsoft Small Business Server (SBS) in the simplest possible way. It may not be appropriate for every customer. However, when you get a situation where the person who owns the server is i…
Citrix XenApp, Internet Explorer 11 set to Enterprise Mode and using central hosted sites.xml file.
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now