We help IT Professionals succeed at work.

Boot Drive

stickney asked
Medium Priority
Last Modified: 2008-03-06
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?
Watch Question

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.


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.

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.
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.

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

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!)



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.
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.