我尝试访问Windows注册表但显示错误。有什么建议?
我正在使用PHP 7.0
。
<?php
// device instance ID
$id = "0060E049DF74EC311000711F";
$keyConst = 'HKEY_LOCAL_MACHINE';
$key = "SYSTEM\CurrentControlSet\services\USBSTOR\Enum";
if (!($reg = reg_open_key($keyConst, $key))) {
throw new Exception("Cannot access registry.");
}
$found = false;
$numDevices = reg_get_value($reg, "Count");
for ($i = 0; $i < $numDevices; $i++) {
$value = reg_get_value($reg, $i);
if (strpos($val, $id) !== false) {
$found = true;
break;
}
}
reg_close_key($reg);
echo "USB drive dongle ", ($found) ? "found" : "not found";
?>