Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I am trying to write a BAT script to produce a grub4dos menu.lst file.

A boot entry in the menu.lst file typically contains a line like:

root (hdx,y)

where x is the hard disk number(first disk hd0) and y is the partition number on the disk (first partition is 0). How can I find the disk and partition numbers of %systemdrive% ?

The script will be running under Windows Vista or 7.

share|improve this question

1 Answer 1

WMIC LogicalDisk GET param1, param2 (etc.)

I'm not sure there is a partition number as such. A list of the WMI classes (e.g. LogicalDisk) that you can inspect is here: MSDN

If you're using Windows 7 the Powershell alternative is:

Get-WmiObject Win32_LogicalDisk | Where {$_.DriveType -eq "3"} | Select param1, param2

EDIT: There is a class for specific partitions: Win32_DiskPartition this does contain an Index property. The Name property will give you both the disk and partition id (but you will have to parse it).

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.