Getting the serial number of the hard drive provided by the manufacturer through PHP

Obtaining the serial number of the hard drive Provided by the manufacturer through PHP: How can this be done? I want to save it to a file.

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

Yes, I need the serial number of the server’s hard drive .

Or can this be done through Adobe AIR? Or can this be done using the C program in 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 to a hard drive? How does it differ from the manufacturer's serial number?

 wmic DISKDRIVE GET SerialNumber 

Only displays the following text on my Vista machine:

Serialnumber

On my XP machine, the command is not recognized.

+6
php serial-number hard-drive
source share
9 answers

Returns the serial number of the drive. If you work with several disks, you will get several results. Just run it with shell_exec .

 wmic DISKDRIVE GET SerialNumber 

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

My result in Vista:

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

I do not know if all hard drives contain a serial number for the OS.

The wmic command seems to be available only in professional versions of Windows XP, Windows Vista, and Windows 7.

+8
source share

PHP itself does not have access to hardware like this.

You have to either

  • use your operating system command and name it using system() or exec()
  • write a PHP extension that will return information to you

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

+5
source share
 hdparm -i /dev/sdX 

what's on linux but not sure about windows. You can do this via "system ()"

Take 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-4f -accd-1063c6bfd559 & lang = zh & cr = HK & sloc = & p = 1

Maybe the way forward.

In addition, when I ran "dir" on the command line, it shows:

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

Is this what you are looking for?

+2
source share

I can’t tell you the answer, but I think you have to look in the direction of extensions (maybe even write one). I doubt that this is what the PHP core has.

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

+1
source share

Do you need a hard drive from a server or client? PHP runs on the server, so getting it directly from the client is not possible for me.

The manual suggests executing commands on your server: http://nl2.php.net/manual/en/ref.exec.php

Unfortunately, I miss Unix for you to get hdd TV shows.

0
source share

you can use

  $hdserial =`wmic DISKDRIVE GET SerialNumber 2>&1` 

or

  $hdserial =`wmic bios get serialnumber 2>&1` 

Then you can repeat it.

Based on the prompts from Patrick Daryll Glandien, you can follow these steps on nix based machines. $ hdserial = hdparm -I /dev/hda

hdparm -i /dev/sda returns less information. But since hdparm needs root access, it did not work with php for me.

The '2> & 1' part is used here from the sentence .

0
source share

Try using this code correctly.

 <?php function GetVolumeLabel($drive) { // Try to grab the volume name if (preg_match('#Volume Serial Number is (.*)\n#i', shell_exec('dir '.$drive.':'), $m)) { $volname = ' ('.$m[1].')'; } else { $volname = ''; } return $volname; } $serial = str_replace("(","",str_replace(")","",GetVolumeLabel("c"))); echo $serial; ?> 
0
source share

On a * nix-based machine, you can also use ls /dev/disk/by-id/ because hdparm requires root permission (see Patrick Daryll G. ).

 <?php exec($command.' 2>&1', $output); echo 'HDD: '.$output[0].'<br>'; $outputs = explode('_', $outputs[0]); $outputs = end($outputs); echo 'HDD-SN: '.$output.'<br>'; 

and you get something like this

 HDD: ata-HGST_XXX1234567890XX_ABCD123456789X // <connection>-<hdd_model>_<hdd_sn> HDD-SN: ABCD123456789X // Your HDD Serial Number 
0
source share

Do the following with shell_exec (check if necessary on the command line):

 wmic path win32_physicalmedia get Tag,SerialNumber 

DISKDRIVE does not receive the actual serial number for my drive, which shows the IDE connected through the channel. above seemed to get actual serial numbers for all of my drives. The tag will also return you what type of drive, which may be useful for identifying different drives.

Output Example:

 SerialNumber Tag WD-WX55D33JQNZ4 \\.\PHYSICALDRIVE4 S1OKIJNH938475 \\.\PHYSICALDRIVE0 WD-CV44HJ5L765Y \\.\PHYSICALDRIVE1 WD-WX41D65SD1UU \\.\PHYSICALDRIVE2 WD-WXB1SD3OIJHG \\.\PHYSICALDRIVE3 \\.\CDROM0 
0
source share

All Articles