Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Can Perl read the hard drive registration #?

by Anonymous Monk
on Mar 20, 2004 at 16:33 UTC ( [id://338312]=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Is it possible to have Perl read the registration numbers for the hard drive(s) installed on the system? Might sound like an odd question but I don't know what to try searching for on Cpan.
  • Comment on Can Perl read the hard drive registration #?

Replies are listed 'Best First'.
Re: Can Perl read the hard drive registration #?
by calin (Deacon) on Mar 20, 2004 at 17:13 UTC

    Try being more specific. What operating system, what do you mean by "registration numbers"?

    For example, you can query a drive on capabilities and vendor strings under Linux with the hdparm command:

    # hdparm -i /dev/hda /dev/hda: Model=WDC WD307AA-00BAA0, FwRev=10.09K11, SerialNo=WD-WMA2F2556865 Config={ HardSect NotMFM HdSw>15uSec SpinMotCtl Fixed DTR>5Mbs FmtGap +Req } RawCHS=16383/16/63, TrkSize=57600, SectSize=600, ECCbytes=40 BuffType=DualPortCache, BuffSize=2048kB, MaxMultSect=16, MultSect=1 CurCHS=16383/16/63, CurSects=16514064, LBA=yes, LBAsects=60074784 IORDY=on/off, tPIO={min:120,w/IORDY:120}, tDMA={min:120,rec:120} PIO modes: pio0 pio1 pio2 pio3 pio4 DMA modes: mdma0 mdma1 mdma2 udma0 udma1 *udma2 udma3 udma4 AdvancedPM=no WriteCache=enabled Drive Supports : Reserved : ATA-1 ATA-2 ATA-3 ATA-4

    And if the serial number is what you're looking for, here's a Perl script to extract it:

    #!/usr/bin/perl my $query = qx{hdparm -i /dev/hda} or die $!; print "HDD serial number is: $1\n" if $query =~ m/SerialNo=([^,\s]+)/s;

    The output on my system is:

    HDD serial number is: WD-WMA2F2556865

      I am on Windows XP but I plan on running this on my server to people can run it web-based if possible? Or will it search my server rather than their hard drive?

      I get an error while running your script though "'hdparam' is not recognized as an internal or external command...".

      Thanks.

        It'll show them the info about your servers Hard drive... And as far as I know, there's no way to show their hard drives info... But, just in case you want it for some other reason, try the vol command in WinXP. atm, I don't have time to work out a script to just get the serial number. But, the output is as follows (on my machine at least):

        Volume in drive C has no label. Volume Serial Number is 7C9B-238A
        Just Another Perl Alchemist

        hdparm is a Linux-only command, as I said in the original reply. Also you need root privileges to run it.

        As of Windows XP, you're out of luck with me... ;)

Re: Can Perl read the hard drive registration #?
by sulfericacid (Deacon) on Mar 20, 2004 at 18:24 UTC
    #!/usr/bin/perl use Win32::DriveInfo; ($VolumeName, $VolumeSerialNumber, $MaximumComponentLength, $FileSystemName, @attr) = Win32::DriveInfo::VolumeInfo('c'); print "$VolumeSerialNumber";
    Seems to do what you want.


    "Age is nothing more than an inaccurate number bestowed upon us at birth as just another means for others to judge and classify us"

    sulfericacid
Re: Can Perl read the hard drive registration #?
by Theo (Priest) on Mar 20, 2004 at 20:21 UTC
    If this is to be used as copy protection or to ensure the program is only run on the original computer, you need to consider what will happen if the user reformats or replaces their hard drive.

    -Theo-
    (so many nodes and so little time ... )

Re: Can Perl read the hard drive registration #?
by Mr. Muskrat (Canon) on Mar 20, 2004 at 18:56 UTC

    Clarify please. Do you want the hard drive serial number or the volume serial number?

    The hard drive serial number is assigned by the hard drive manufacturer. The volume serial number is a random number assigned by Windows when the volume is formatted.

Re: Can Perl read the hard drive registration #?
by Mr. Muskrat (Canon) on Mar 27, 2004 at 04:12 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://338312]
Approved by davido
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2024-04-16 05:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found