For example, if I'm booted from Windows PE, or remoting into a system using psexec or another command-line based method. I know that diskpart.exe allows you to set the active partition, but I can't find any way of seeing which partition is currently active.
Hopefully there's a simple answer and I'm just missing it ...
shareimprove this question

4 Answers

up vote12down voteaccepted
+100
Only way I know how to do this is close to what @Maximus put but do the following:
diskpart.exe
select volume 1
detail partition
The output will indicate
Active: Yes/No
For example: enter image description here
You have to go through each volume to find which ones are Active and which ones are not. You can use Diskpart's list volume command to show all volumes and find the one you want to check first.
shareimprove this answer
You can use wmic to do this. You may wish to export it to a text file (>output.txt) and view without word wrapping since the tabular output can get very wide.
To list all partitions (look at the BootPartition member to check if it's marked as active):
wmic partition
To list just active partitions, filter with where:
wmic partition where BootPartition=true
To filter which columns are displayed, use get:
wmic partition where BootPartition=true get DeviceID,Size
Also:
wmic partition get DeviceID,Size,BootPartition
For more information on partition members, see the Win32_DiskPartition documentation.
BootPartition
Data type: boolean Access type: Read-only
Partition is the active partition. The operating system uses the active partition when booting from a hard disk.

Take a look at the WQL syntax for more information on the usage of where. Take a look at wmic partition get /? for more information on get.

With wmic you have added advantages with remote management using the /node:<servername or ip> switch (see wmic /node /? for more information. As per Microsoft:
WMIC can be used from any computer with WMIC enabled to remotely manage any computer with WMI. WMIC does not have to be available on the remotely managed computer in order for WMIC to manage it.

If you can figure out some way of programmatically (e.g. batch script) getting the drive letter from the disk and partition index, you may wish to use a for loop with the members DiskIndex and Index (disk and partition indexes, respectively).
shareimprove this answer
As a fans of Cygwin, I'll suggest use the fdisk utility from the util-linux package to do this if you're not using GPT.
If you're remoting into a system, you need to install Cygwin on that system.
If you're booting from Windows PE, you can manually download the packages and extract them using a proper decompressor which can handle .tar.bz2 files.
Packages needed to download to run fdisk
Example (1 hdd, 1 flash drive)
$ uname -svr
CYGWIN_NT-5.1 1.7.17(0.262/5/3) 2012-10-19 14:39

$ /usr/sbin/fdisk -l | grep /dev/
Disk /dev/sda: 320.1 GB, 320072933376 bytes
/dev/sda1   *          63    83891429    41945683+   7  HPFS/NTFS/exFAT
/dev/sda2        83891430   625137344   270622957+   f  W95 Ext'd (LBA)
/dev/sda5        83891493   503332514   209720511    7  HPFS/NTFS/exFAT
/dev/sda6       503332578   625137344    60902383+   7  HPFS/NTFS/exFAT
Disk /dev/sdb: 8065 MB, 8065646080 bytes
/dev/sdb1   *          32    15753214     7876591+   b  W95 FAT32
shareimprove this answer
select disk 0
detail disk
Look into last column (System)?
shareimprove this answer
   
What if it is not a system disk; how can you tell if the partition is active? For example, if you have a second disk with a FAT32 partition from which XP is dual-booted, does it say System? – Synetech Jul 16 '12 at 20:55
   
I thought at first this was the correct answer, but it turns out that this only shows which partition the running instance of Windows was booted from. If the active partition has changed since then, or if you are booted from removable media, it doesn't work. – Harry Johnston Jul 16 '12 at 21:03
   
But how about asterisk in detail disk (first column)? May be it is the answer? – Maximus Jul 16 '12 at 21:10
   
No, the asterisk shows you which volume (if any) is currently selected (SELECT VOLUME or SELECT PARTITION). – Harry Johnston Jul 16 '12 at 23:20