• C

Boot Drive

I would like to know exactly how to determine the boot drive of a PC. I need to locate the proper Autoexec.bat file which would be in the root directory of the boot drive. How do I determine the boot drive?
Who is Participating?
sprinkmeierConnect With a Mentor Commented:
Autoexec.bat implies you're using DOS.
As far as I know, Dos boot from the first primary parition on the first physical disk, which is allways C:
(once you have booted up, of course)

Are you trying to determine the boot drive before or after you have booted up?
If it' after, the answer is 'C:' (else you could try interogating the PATH environement variable for x:\DOS. not fool proof, but should work 99% of the time)
If it's before, you may not be able to tell 'cos of things like BootManager.

The boot procedure defined in on-board BIOS. If your BIOS
hasn't option to use ANY drive to boot - you have to select
drive C to boot and *WRITE YOUR-OWN BOOT SECTOR* on C for
switch to another drive. If you do not want to write it -
by a boot dispatcher, there are a lot of programs like this
on the market and, I think, I saw some shareware.

stickneyAuthor Commented:
What I'm really looking for is how programatically (using C or C++) determine the boot drive of ANY PC (the drive their system was booted from). If possible, I would like to see some sample code. Thanks.
Build your data science skills into a career

Are you ready to take your data science career to the next step, or break into data science? With Springboard’s Data Science Career Track, you’ll master data science topics, have personalized career guidance, weekly calls with a data science expert, and a job guarantee.

You have to rewrite on-chip BIOS to select a boot sector
will be loaded first or rewrite boot sector on first bootable
partition (see FDISK) to *CONTINUE* high level booting
(OS I/O system). Both things must be implemented in

Maybe somebody can help you if you tell what computer, operating system and language you are using.
After the computer booted it is too late
to determine boot drive. Autoexec.bat started
after the DOS loaded. Only 2 ways:
   or BIOS (very dangerous!)


stickneyAuthor Commented:
I'm trying to determine where the boot drive is after I have booted up. I appreciate all of your input. I thought that there must be a way to derive this information. Within InstallShield there is a command which will return the Boot drive. It makes me wonder how they determine the boot drive.
The easiest way to determine which is the boot drive is to read the partition table for the drives. The partition table is one sector in size. It has four partition entries. If 0 is the starting offset in memory for the partition table, each entry is 10h bytes in size, being at 1BEh,1CEh,1DEh,and 1EEh. At the first byte of these four offsets is the boot flag. The boot flag is 80h if it is bootable, otherwise it is 0h. Hope this answers your question. Sorry you have to do so much low level disk stuff, its the only way I know, email me if you need further explanation.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.