function detectInkscapePath() { if (detectOS(HK_OS_WINDOWS)) { // automatic attempt to recognize Inkscape path for Windows $inkPath = "Inkscape"; $inkBin = "inkscape.com"; // try standard locations if (isset($_SERVER['ProgramFiles(x86)']) && file_exists($tryPath = "{$_SERVER['ProgramFiles(x86)']}\\{$inkPath}\\{$inkBin}")) { return $tryPath; } if (isset($_SERVER['ProgramW6432']) && file_exists($tryPath = "{$_SERVER['ProgramW6432']}\\{$inkPath}\\{$inkBin}")) { return $tryPath; } // try to read from registry if (!extension_loaded('com_dotnet')) { dl('php_com_dotnet.dll'); } $sh = new COM('WScript.Shell'); $checkKeys = ["HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\App Paths\\inkscape.exe\\", "HKCR\\inkscape.svg\\shell\\open\\command\\"]; foreach ($checkKeys as $rk) { try { $regRead = $sh->regRead($rk); // no need to check if read passed, because if not, the rest of block won't be executed $regRead = str_replace('%1', '', $regRead); $tryPath = dirname(trim($regRead, '" ')) . "\\{$inkBin}"; if (file_exists($tryPath)) { return $tryPath; } } catch (Exception $e) { } } return ''; // not found } else { // automatic attempt to recognize Inkscape path for other systems if ($shOut = shell_exec('command -v inkscape')) { return trim($shOut); } // passes if Inkscape is within default path // try standard location $tryPath = '/usr/bin/inkscape'; if (file_exists($tryPath)) { return $tryPath; } return ''; // not found } }
/** * Function reads the registry value of the specified path * @param <string> $registryPath Path of the registry value to be read * @return <string> Registry value * @category Extra * <code> * $result = Extra::readRegistry('registry\\path'); * </code> */ function readRegistry($registryPath) { try { $Wshshell = new COM('WScript.Shell'); $data = $Wshshell->regRead($registryPath); return $data; } catch (Exception $err) { return $err->getMessage(); } }
public function read($key) { return $this->shell->regRead($key); }