views:

2951

answers:

7

Getting Serial Number of the Hard Drive Provided by the manufacturer through PHP : How can it be done? I want to store it in a file.

OS : windows 2000,XP,ME,Vista...

Yes, I want the serial number of the hard drive of the Server.

Or can it be done through Adobe AIR? Or can it be done through a C program on Windows?

C:\Documents and Settings\Administrator>dir
 Volume in drive C has no label.
 Volume Serial Number is BC16-5D5F

Is this number : BC16-5d5f unique for a hard drive? How is it different from the manufacturer given serial number?

This command
**wmic DISKDRIVE GET SerialNumber**
Displays only the following text
on my Vista Machine : 
SerialNumber

On my XP machine,
the command is unrecognized
A: 

Do you want the hard drive from the server or a client? PHP runs on the server so getting it straight from the client doens't seem possible to me.

The manual suggest you can execute commands on you server: http://nl2.php.net/manual/en/ref.exec.php

Unfortunately I don't enough Unix to get you hdd serials.

MrHus
+1  A: 
hdparm -i /dev/sdX

that's on linux, not sure on windows though. You could execute that via "system()"

Have a look at http://www.microsoft.com/communities/newsgroups/en-us/default.aspx?dg=microsoft.public.hk.msdn.connection&tid=e41f0af2-2e76-4be6-9b7b-636e79ac0491&cat=zh_HK_3b03d742-993a-4f96-accd-1063c6bfd559&lang=zh&cr=HK&sloc=&p=1

Might be a way forward.

Also, when I ran a "dir" on the command prompt, it shows:

C:\Documents and Settings\Administrator>dir
 Volume in drive C has no label.
 Volume Serial Number is BC16-5D5F

Is that what you're looking for?

Andrei Serdeliuc
That volume (i.e. partition) serial number.
vartec
Oh, thanks! I'll keep that in mind.
Andrei Serdeliuc
Is this number BC16-5d5f unique for a hard drive?How is this number generated BTW and how is it different fromthe manufacturer given serial number?
dta
A: 

I can't tell you the answer, but I guess you'll have to look in the direction of extensions (maybe even writing one yourself). I doubt this is something PHP's core has.

Edit: I forgot about the raw power of "exec" :-/

Bart van Heukelom
+4  A: 

PHP itself has no way of accessing the hardware like that.

You will have to either

  • use a command of your operating system and call it with system() or exec()
  • write an extension for PHP that will return you the information

If you are on Linux and have the necessary privileges and configuration you can use $r = system("hdparm -I /dev/hda"); (replace hda with your hd) to get the serial number of a given hard drive.

Patrick Daryll Glandien
A: 

In C

vartec
I tried the demo given on the project page.It didn't work for me.It didn't display any number at all.
dta
+3  A: 

The following returns the disk serial number. Should work with multiple drives, you'll just get multiple results. Just run it with shell_exec.

wmic DISKDRIVE GET SerialNumber

wmic.exe is located in your windows system32 folder. And wmic does exist on WinXP, Ive used it there myself.

My result on Vista:

C:\Windows\System32>wmic DISKDRIVE GET SerialNumber
SerialNumber
20202020202054534241354c4*snip*

I do not know if all harddrives provides the serial number to the OS.

OIS
A: 

serial number of disks (local info) wmic path win32_physicalmedia get serialnumber

serial number of disks (remote info) wmic /node:"remote_computername" path win32_physicalmedia get serialnumber

Slash75