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 WDiskDrives.pl 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 ); my @CAPABILITIES = ( 'Unknown', 'Other', 'Sequential Access', 'Random Access', 'Supports +Writing', '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 ); } __DATA__ F:\>wdd2.pl Name: \\.\PHYSICALDRIVE0 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 +0\345935334552454C202020202020202020202020 Signature: 169678702 Partitions: 3 Size: 122,935,034,880 bytes Capabilities: Random Access Supports Writing Total drive space: 122,935,034,880 bytes

In reply to (Win32) Hard Drive Information by Mr. Muskrat

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.