简体   繁体   English

如何使用php获取主硬盘的序列号

[英]How I can get the serial number of the primary hard disk using php

I was using: 我正在使用:

$serial =  shell_exec('wmic DISKDRIVE GET SerialNumber 2>&1');

But with this I get all the hard disk serial number, I just want the serial number of the primary hard disk, in my case "c". 但是有了这个,我得到了所有硬盘的序列号,我只想要主硬盘的序列号,在我的例子中是“ c”。 I tried with this: 我尝试了这个:

wmic path win32_diskdrive where deviceid="\\\\.\\PHYSICALDRIVE0" get serialnumber

It works fine in the windows console, but I tried to use it with exec like this: 它在Windows控制台中工作正常,但我尝试将其与exec一起使用,如下所示:

$serial =  exec('wmic path win32_diskdrive where deviceid="\\\\.\\PHYSICALDRIVE0" get serialnumber');

But I just get "" 但我得到“”

exec returns only the last line of output. exec仅返回输出的最后一行。 Either give it its output argument, which it'll fill in with each line, or use shell_exec instead. 给它提供输出参数,然后在每一行中填充它,或者使用shell_exec代替。 Also double up on your backslashes so they're escaped properly. 同时在您的反斜杠上加倍,以使它们正确逃脱。 Eg: 例如:

exec('wmic path win32_diskdrive where deviceid="\\\\\\\\.\\\\PHYSICALDRIVE0" get serialnumber', $out);
var_dump($out);

or 要么

$serial = shell_exec('wmic path win32_diskdrive where deviceid="\\\\\\\\.\\\\PHYSICALDRIVE0" get serialnumber');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM