Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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