<p>I'm need to find a method to programmatically determine which disk drive Windows is using to boot. In other words, I need a way from Windows to determine which drive the BIOS is using to boot the whole system. </p>

<p>Does Windows expose an interface to discover this? With how big the Windows API is, I'm hoping there is something buried in there that might do the trick.</p>

<p>Terry</p>

<p>p.s. Just reading the first sectors of the hard disk isn't reveling anything. On my dev box I have two hard disks, and when I look at the contents of the first couple of sectors on either of the hard disks I have a standard boiler plate MBR.</p>

<p>Edit to clarify a few things.
The way I want to identify the device is with a string which will identify a physical disk drive (as opposed to a logical disk drive). Physical disk drives are of the form "\\.\PHYSICALDRIVEx" where x is a number. On the other hand, a logical drive is identified by a string of the form, "\\.\x" where x is a drive letter.</p>

<p>Edit to discuss a few of the ideas that were thrown out.
Knowing which logical volume Windows used to boot doesn't help me here. Here is the reason. Assume that C: is using a mirrored RAID setup. Now, that means we have at least two physical drives. Now, I get the mapping from Logical Drive to Physical Drive and I discover that there are two physical drives used by that volume. Which one did Windows use to boot? Of course, this is assuming that the physical drive Windows used to boot is the same physical drive that contains the MBR. </p>

[{'answer_id': 40347, 'author': 'UnkwnTech', 'author_id': 115, 'author_profile': 'https://Stackoverflow.com/users/115', 'pm_score': 3, 'selected': False, 'text': '<p>Unless C: is not the drive that windows booted from.<br />Parse the %SystemRoot% variable, it contains the location of the windows folder (i.e. c:\\windows).</p>\n'}, {'answer_id': 40355, 'author': 'Rob Walker', 'author_id': 3631, 'author_profile': 'https://Stackoverflow.com/users/3631', 'pm_score': 2, 'selected': False, 'text': '<p>There is no boot.ini on a machine with just Vista installed.</p>\n\n<p>How do you want to identify the drive/partition: by the windows drive letter it is mapped to (eg. c:\\, d:) or by how its hardware signature (which bus, etc).</p>\n\n<p>For the simple case check out <a href="http://msdn.microsoft.com/en-us/library/ms724373(VS.85).aspx" rel="nofollow noreferrer">GetSystemDirectory</a></p>\n'}, {'answer_id': 40362, 'author': 'Duncan Smart', 'author_id': 1278, 'author_profile': 'https://Stackoverflow.com/users/1278', 'pm_score': 1, 'selected': False, 'text': '<p>Try HKEY_LOCAL_MACHINE\\SYSTEM\\Setup\\SystemPartition</p>\n'}, {'answer_id': 40682, 'author': 'Chris Gillum', 'author_id': 2069, 'author_profile': 'https://Stackoverflow.com/users/2069', 'pm_score': 2, 'selected': False, 'text': '<p>You can use WMI to figure this out.  The <a href="http://msdn.microsoft.com/en-us/library/aa394078.aspx" rel="nofollow noreferrer">Win32_BootConfiguration</a> class will tell you both the logical drive and the physical device from which Windows boots.  Specifically, the Caption property will tell you which <em>device</em> you\'re booting from.</p>\n\n<p>For example, in powershell, just type <strong>gwmi Win32_BootConfiguration</strong> to get your answer.</p>\n'}, {'answer_id': 40753, 'author': 'Mark Brackett', 'author_id': 2199, 'author_profile': 'https://Stackoverflow.com/users/2199', 'pm_score': 2, 'selected': False, 'text': "<p>That depends on your definition of which disk drive Windows used to boot. I can think of 3 different answers on a standard BIOS system (who knows what an EFI system does):</p>\n\n<ol>\n<li>The drive that contains the active MBR</li>\n<li>The active partition, with NTLDR (the system partition)</li>\n<li>The partition with Windows on it (the boot partition)</li>\n</ol>\n\n<p>2 and 3 should be easy to find - I'm not so sure about 1. Though you can raw disk read to find an MBR, that doesn't mean it's the BIOS boot device this time or even next time (you could have multiple disks with MBRs).</p>\n\n<p>You really can't even be sure that the PC was started from a hard drive - it's perfectly possible to boot Windows from a floppy. In that case, both 1 and 2 would technically be a floppy disk, though 3 would remain C:\\Windows.</p>\n\n<p>You might need to be a bit more specific in your requirements or goals.</p>\n"}, {'answer_id': 18424806, 'author': 'JD.', 'author_id': 300041, 'author_profile': 'https://Stackoverflow.com/users/300041', 'pm_score': 4, 'selected': False, 'text': '<ol>\n<li>Go into <code>Control Panel</code></li>\n<li><code>System and Security</code></li>\n<li><code>Administrative Tools</code></li>\n<li>Launch the <code>System Configuration</code> tool</li>\n</ol>\n\n<p>If you have multiple copies of Windows installed, the one you are booted with will be named such as:</p>\n\n<pre><code>Windows 7 (F:\\Windows)\nWindows 7 (C:\\Windows) : Current OS, Default OS\n</code></pre>\n'}, {'answer_id': 34293003, 'author': 'ST3', 'author_id': 1237747, 'author_profile': 'https://Stackoverflow.com/users/1237747', 'pm_score': 0, 'selected': False, 'text': '<p>You can try use simple command line. <a href="https://technet.microsoft.com/en-us/library/cc709667%28v=ws.10%29.aspx" rel="nofollow">bcdedit</a> is what you need, just run cmd as administrator and type <code>bcdedit</code> or <code>bcdedit \\v</code>, this doesn\'t work on XP, but hope it is not an issue.</p>\n\n<p>Anyway for XP you can take a look into <code>boot.ini</code> file.</p>\n'}, {'answer_id': 64396478, 'author': 'Mark', 'author_id': 14465066, 'author_profile': 'https://Stackoverflow.com/users/14465066', 'pm_score': 2, 'selected': False, 'text': '<p>You type diskpart, list disk and check disks for boot.<br />\nEx:</p>\n<pre><code>dispart \nlist disk \nselect disk 0 \ndetail disk\n</code></pre>\n<p>The disk with Boot volume is disk with windows installed:</p>\n<p><a href="https://i.stack.imgur.com/gtfAP.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/gtfAP.png" alt="enter image description here" /></a></p>\n'}, {'answer_id': 65987496, 'author': 'sandstorm', 'author_id': 9854447, 'author_profile': 'https://Stackoverflow.com/users/9854447', 'pm_score': 0, 'selected': False, 'text': '<p><strong>a simpler way</strong>\nsearch downloads in the start menu and click on downloads in the search results to see where it will take you the drive will be highlighted in the explorer.</p>\n'}, {'answer_id': 67981692, 'author': 'Peter Futterleib', 'author_id': 16230464, 'author_profile': 'https://Stackoverflow.com/users/16230464', 'pm_score': 0, 'selected': False, 'text': '<p>On Windows 10.\nOpen &quot;Computer Management&quot;\nLook for &quot;Storage&quot; in list &quot;left top  side of page&quot;\nselect &quot;Disk Management&quot;\nOn section of page showing the list of disks and the partitions find the disk that has the partition assigned as drive C:\nOn that disk containing C: partition\nUse the right mouse button to select the Square section containing The Disk Number, Type of drive and size in GB . When menu opens select the Properties.\nA window will open showing what drive hardware was used.</p>\n'}]
['https://Stackoverflow.com/questions/40335', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/2171/']