Visual Basic WMI System Services
Win32_DiskPartition: WMI Disk Partition Info
     
Posted:   Wednesday October 30, 2002
Updated:   Monday November 28, 2011
     
Applies to:   VB5, VB6
Developed with:   VB6, Windows XP
OS restrictions:   Windows NT, 2000, XP. See Prerequisites below.
Author:   VBnet - Randy Birch
     

Related:  

 
     
 Prerequisites
Windows Script Host is built into Microsoft Windows 98, 2000, ME and XP. If you are running Windows 95 or NT4, you can download Windows Script Host from the Microsoft Windows Script Technologies Web site at http://msdn.microsoft.com/scripting/. Some information is not returned on non-NT-based systems.

A reference set in Projects / References to the Microsoft WMI Scripting Library.


Win32_DiskPartition represents the capabilities and management capacity of a partitioned area of a physical disk on a Windows system. Example: Disk #0, Partition #1.

This demo and illustration shows only some of the available information from the class. For a complete listing see the Comments section below. Note that some systems may not return information in all class properties.

 BAS Module Code
None.

 Form Code
To a form add a command button (Command1) and a listbox (List1). Set a reference in Projects / References to the Microsoft WMI Scripting Library, and add the following to the form:

Option Explicit
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Copyright ©1996-2011 VBnet/Randy Birch, All Rights Reserved.
' Some pages may also contain other copyrights by the author.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Distribution: You can freely use this code in your own
'               applications, but you may not reproduce 
'               or publish this code on any web site,
'               online service, or distribute as source 
'               on any media without express permission.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Sub Command1_Click()

   Call wmiWin32DiskPartition
   
End Sub


Private Sub Form_Load()
   
   Command1.Caption = "wmiWin32DiskPartition"

End Sub


Private Sub wmiWin32DiskPartition()
      
   Dim objset  As SWbemObjectSet
   Dim obj     As SWbemObject

   Set objset = GetObject("winmgmts:{impersonationLevel=impersonate}"). _
                                      InstancesOf("Win32_DiskPartition")
   
   On Local Error Resume Next

   For Each obj In objset

      With List1
         .AddItem "DeviceID: " & obj.DeviceID
         .AddItem "DiskIndex: " & obj.DiskIndex
         .AddItem "Index: " & obj.Index
         .AddItem "BlockSize: " & obj.BlockSize
         .AddItem "Bootable: " & obj.Bootable
         .AddItem "BootPartition: " & obj.BootPartition
         .AddItem "NumberOfBlocks: " & FormatNumber(obj.NumberOfBlocks)
         .AddItem "PrimaryPartition: " & obj.PrimaryPartition
         .AddItem "Size: " & FormatNumber(obj.Size, 0)
         .AddItem ""
      End With
        
   Next
   
End Sub
 Comments
All information returned in the Win32_DiskPartition class (note that some systems may not return information in all class properties):
   
uint16 Access;
uint16 Availability;
uint64 BlockSize;
boolean Bootable;
boolean BootPartition;
string. Caption;
uint32 ConfigManagerErrorCode;
boolean ConfigManagerUserConfig;
string. CreationClassName;
string Description;
string DeviceID;
uint32 DiskIndex;
boolean ErrorCleared;
string ErrorDescription;
string ErrorMethodology;
uint32 HiddenSectors;
uint32 Index;
datetime InstallDate;
uint32 LastErrorCode;
string Name;
uint64 NumberOfBlocks;
string PNPDeviceID;
uint16 PowerManagementCapabilities[];
boolean PowerManagementSupported;
boolean PrimaryPartition;
string Purpose;
boolean RewritePartition;
uint64 Size;
uint64 StartingOffset;
string Status;
uint16 StatusInfo;
string SystemCreationClassName;
string SystemName;
string Type;

 
 

PayPal Link
Make payments with PayPal - it's fast, free and secure!

 
 
 
 

Copyright ©1996-2011 VBnet and Randy Birch. All Rights Reserved.
Terms of Use  |  Your Privacy

 

Hit Counter