Managing Disk Partitions

Microsoft® Windows® 2000 Scripting Guide

microsoft windows 2000 scripting guide

« Previous | Next »   

A partition is a structural division of a physical disk drive. Although a drive can contain a single partition, larger volumes are often divided into multiple partitions. This is why you might have drives C, D, and E even though your computer has only a single physical hard disk.

The Windows 2000 operating system supports the following partition types:

  • Primary partition. This is the only type of partition that can have an operating system installed. Each drive can have as many as four primary partitions, each assigned a different drive letter.
  • Extended partition. An additional partition that can be subdivided into multiple logical drives, each assigned a unique drive letter. A drive can have only one extended partition; however, you can divide this partition into multiple logical drives. This enables a disk to have more than just the four allowed primary partitions.
  • System partition. Any primary partition containing an operating system.

Partitions can tell you how a physical disk drive is actually being used. By examining the physical partitions on a disk, you can determine the following types of things:

  • How the disk has been divided into logical drives.
  • If there is unpartitioned space available on the disk. This can be determined by subtracting the size of all the partitions on a disk from the size of the disk itself.
  • If you can boot the computer from that disk (that is, does the disk contain a boot partition).

All these questions can be resolved by using the Win32_DiskPartition class. A subset of partition properties available through this class is shown in Table 10.2.

Table 10.2   Win32_DiskPartition Properties

PropertyDescription
BlockSizeSize (in bytes) of the blocks that form this partition.
BootableBoolean value indicating whether the computer can be booted from this partition.
BootPartition

Boolean value that indicates whether the partition is the active partition. The operating system uses the active partition when booting from a hard disk.
DeviceIDUnique identifier that differentiates the disk drive and partition from the rest of the system.
DiskIndexIndex number of the disk containing this partition.
IndexIndex number of the partition.
NameLabel by which the object is known.
NumberOfBlocksTotal number of consecutive blocks, each block being the size of the value contained in the BlockSize property. The total size of the disk can be calculated by multiplying the value of the BlockSize property by the value of this property. If the value of BlockSize is 1, this property is the total size of the disk.
PrimaryPartitionBoolean value indicating whether this is the primary partition on the computer.
SizeTotal size of the partition in bytes.
StartingOffsetStarting offset (in bytes) of the partition.
SystemNameName of the computer where the partition is installed.
TypeType of the partition. Values are:
  • Unused
  • 12-bit FAT
  • Xenix Type 1
  • Xenix Type 2
  • 16-bit FAT
  • Extended Partition
  • MS-DOS® V4 Huge
  • Installable File System
  • PowerPC Reference Platform
  • UNIX
  • NTFS file system
  • Win95 with Extended Int 13
  • Extended with Extended Int 13
  • Logical Disk Manager
  • Unknown

Scripting Steps

Listing 10.2 contains a script that enumerates the properties of all the disk partitions on a computer. To carry out this task, the script must perform the following steps:

  1. Create a variable to specify the computer name.
  2. Use a GetObject call to connect to the WMI namespace root\cimv2, and set the impersonation level to "impersonate."
  3. Use the ExecQuery method to query the Win32_DiskPartition class.

    This query returns a collection consisting of all the disk partitions on all the disk drives installed on the computer.

  4. For each disk partition in the collection, echo the value of properties such as the DeviceID, the partition size, and whether the partition is bootable.

Listing 10.2   Enumerating Disk Partition Properties

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 
strComputer = "." Set objWMIService = GetObject("winmgmts:" _     & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colDiskPartitions = objWMIService.ExecQuery _     ("SELECT * FROM Win32_DiskPartition") For each objPartition in colDiskPartitions     Wscript.Echo "Block Size: " & objPartition.BlockSize        Wscript.Echo "Bootable: " & objPartition.Bootable        Wscript.Echo "Boot Partition: " & objPartition.BootPartition     Wscript.Echo "Description: " & objPartition.Description     Wscript.Echo "Device ID: " & objPartition.DeviceID        Wscript.Echo "Disk Index: " & objPartition.DiskIndex        Wscript.Echo "Index: " & objPartition.Index        Wscript.Echo "Name: " & objPartition.Name        Wscript.Echo "Number Of Blocks: " & _         objPartition.NumberOfBlocks        Wscript.Echo "Primary Partition: " & _         objPartition.PrimaryPartition        Wscript.Echo "Size: " & objPartition.Size        Wscript.Echo "Starting Offset: " & _         objPartition.StartingOffset        Wscript.Echo "Type: " & objPartition.Type    Next

send us your feedback Send us your feedback « Previous | Next »   


Microsoft Windows 2000 Scripting Guide(c) Automating System Administration 2003
Microsoft Windows 2000 Scripting Guide(c) Automating System Administration 2003
ISBN: N/A
EAN: N/A
Year: 2004
Pages: 635

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net