Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

(Win32) Hard Drive Information

by Mr. Muskrat (Canon)
on Mar 27, 2004 at 04:10 UTC ( #340212=snippet: print w/replies, xml ) Need Help??

Gather all sorts of information about your hard drives. If you are running Windows XP or Server 2003, that information will include the hard drives serial number if it has one.

This was based heavily on that was the example used in Dave Roth's article on Using WMI to Request Data About Disk Drives.

use strict;
use Win32::OLE qw( in );

  'Unknown', 'Other', 'Sequential Access', 'Random Access', 'Supports 
  'Encryption', 'Compression', 'Supports Removable Media',
  'Manual Cleaning', 'Automatic Cleaning'
my $TotalSize = 0;
my $Machine = shift @ARGV || ".";
$Machine =~ s/^[\\\/]+//;
my $WMIServices = Win32::OLE->GetObject( "winmgmts:{impersonationLevel
+=impersonate,(security)}//$Machine" ) || die;

my (@drives, %serial);

my $DriveCollection = $WMIServices->InstancesOf( "Win32_DiskDrive" );
foreach my $Drive ( in( $DriveCollection ) ) {
  push @drives, $Drive;

my $PhysMedia = $WMIServices->InstancesOf( "Win32_PhysicalMedia" );

foreach my $Drive ( in( $PhysMedia ) ) {
  my $name = (split(/=/, $Drive->{Path_}->relpath))[1];
  $serial{eval $name} = $Drive->{SerialNumber};

foreach my $Drive (@drives) {
  print "Name: $Drive->{Name}\n";
  print "  Manufacturer: $Drive->{Manufacturer}\n";
  print "  Media Type: $Drive->{MediaType}\n";
  print "  Description: $Drive->{Description}\n";
  print "  Drive type: $Drive->{InterfaceType}\n";
  print "  Model: ", $Drive->{Model} || "Unknown", "\n";
  print "  Caption: $Drive->{Caption}\n";
  print "  SerialNumber: $serial{$Drive->{Name}}\n";
  print "  PNPDeviceID: $Drive->{PNPDeviceID}\n";
  print "  Signature: $Drive->{Signature}\n";
  print "  Partitions: $Drive->{Partitions}\n";
  print "  Size: ", FormatNumber( $Drive->{Size} ), " bytes\n";
  print "  Capabilities:\n";
  my $CapabilityList = $Drive->{Capabilities} || [];
  foreach my $Cap ( @{$CapabilityList }  ) {
    print "    $CAPABILITIES[$Cap]\n";
  print "\n";
  $TotalSize += $Drive->{Size};
print "Total drive space: ", FormatNumber( $TotalSize ), " bytes\n";

sub FormatNumber {
    my($Number) = @_;
    while( $Number =~ s/^(-?\d+)(\d{3})/$1,$2/ ){};
    return( $Number );

  Manufacturer: (Standard disk drives)
  Media Type: Fixed hard disk media
  Description: Disk drive
  Drive type: IDE
  Model: Maxtor 6Y120P0
  Caption: Maxtor 6Y120P0
  SerialNumber: Y435RELE
  PNPDeviceID: IDE\DISKMAXTOR_6Y120P0__________________________YAR41BW
  Signature: 169678702
  Partitions: 3
  Size: 122,935,034,880 bytes
    Random Access
    Supports Writing

Total drive space: 122,935,034,880 bytes
Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: snippet [id://340212]
[choroba]: Your votes in your profile?
[ambrus]: pryrt: yes, there is. link "Your votes" from your profile page.
[ambrus]: (That link work two ways: from your own profile page, it lists all your votes; from anyone else's profile page, it lists your votes on that user's nodes only.)
[choroba]: Wow, and I can create an interesting statistics from it
[LanX]: I've also added a link "my votes" to the personal nodelet
[pryrt]: Thanks, that was what I was looking for

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (13)
As of 2017-03-29 13:38 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (351 votes). Check out past polls.