Solved

how can i make a bootable usb drive programatically

Posted on 2008-09-29
7
1,330 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
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 

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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Solid State Drive Performance Tips: Solid state storage technology is now a standard.  After testing and using several different brands and revisions of SSD's over the years I have put together a collection of tips,tools and suggestions that I ha…
When you upgrade from Windows 8 to 8.1 or to Windows 10 or if you are like me you are on the Insider Program you may find yourself with many 450MB recovery partitions.  With a traditional disk that may not be a problem but with relatively smaller SS…
This video Micro Tutorial explains how to clone a hard drive using a commercial software product for Windows systems called Casper from Future Systems Solutions (FSS). Cloning makes an exact, complete copy of one hard disk drive (HDD) onto another d…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

863 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

21 Experts available now in Live!

Get 1:1 Help Now