【问题标题】:How I can get the serial number of the primary hard disk using php如何使用php获取主硬盘的序列号
【发布时间】:2019-03-27 17:19:19
【问题描述】:

我正在使用:

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

但是有了这个我得到了所有的硬盘序列号,我只想要主硬盘的序列号,在我的例子中是“c”。 我试过这个:

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

它在 Windows 控制台中运行良好,但我尝试将它与 exec 一起使用,如下所示:

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

但我只是得到“”

【问题讨论】:

    标签: php windows


    【解决方案1】:

    exec 仅返回输出的最后一行。要么给它它的输出参数,它会用每一行填充,要么使用shell_exec。还要加倍你的backslashes,这样它们就可以正确逃脱。例如:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-05-10
      • 2010-11-24
      • 2014-12-31
      • 2010-12-06
      • 2011-05-04
      • 2016-06-10
      • 2014-01-11
      • 2011-10-20
      相关资源
      最近更新 更多