function stdapi_registry_create_key($req, &$pkt) { my_print("doing stdapi_registry_create_key"); if (is_windows() and is_callable('reg_open_key')) { $root_tlv = packet_get_tlv($req, TLV_TYPE_ROOT_KEY); $base_tlv = packet_get_tlv($req, TLV_TYPE_BASE_KEY); $perm_tlv = packet_get_tlv($req, TLV_TYPE_PERMISSION); dump_array($root_tlv); dump_array($base_tlv); # For some reason the php constants for registry root keys do not have # the high bit set and are 1 less than the normal Windows constants, so # fix it here. $root = ($root_tlv['value'] & ~0x80000000) + 1; $base = $base_tlv['value']; my_print("reg opening '{$root}', '{$base}'"); $key = reg_open_key($root, $base); if (!$key) { my_print("reg open failed: {$key}"); return ERROR_FAILURE; } $key_id = register_registry_key($key); packet_add_tlv($pkt, create_tlv(TLV_TYPE_HKEY, $key_id)); return ERROR_SUCCESS; } else { return ERROR_FAILURE; } }
function __construct($haiv, $key) { $this->h = $haiv; $this->k = $key; $this->r = reg_open_key($this->h, $this->k); $this->shell = new COM('WScript.Shell'); if (!$this->shell) { throw new Exception("Cannot create shell object."); } if (!$this->r) { throw new Exception("Cannot access registry."); } $this->path = self::$HK[$this->h] . '\\' . $this->k; }
<?php /* This script sets up an event source for use by the php syslog() function. */ if (!extension_loaded("win32std")) { @dl("php_win32std.dll"); } $PATH = "SYSTEM\\CurrentControlSet\\Services\\Eventlog\\Application\\PHP-" . phpversion(); $dll = $argv[1]; if (extension_loaded("win32std")) { $key = @reg_create_key(HKEY_LOCAL_MACHINE, $PATH, KEY_ALL_ACCESS); if (!$key) { $key = reg_open_key(HKEY_LOCAL_MACHINE, $PATH, KEY_ALL_ACCESS); } if ($key) { reg_set_value($key, "TypesSupported", REG_DWORD, 7) or die("Types"); reg_set_value($key, "EventMessageFile", REG_SZ, $dll) or die("EventMessageFile"); syslog(LOG_NOTICE, "Registered PHP Event source"); } else { echo "Could not register event source\n"; } } /* let's also generate/update the bundled .reg file */ $dll = addslashes($dll); file_put_contents("win32/syslog.reg", <<<REG REGEDIT4 [HKEY_LOCAL_MACHINE\\{$PATH}] "TypesSupported"=dword:00000007 "EventMessageFile"="{$dll}" REG
} /* Sound exemple */ if (!win_play_wav("%WINDIR%\\Media\ringin.wav", 1)) { echo "Unable to play sound !\n"; } else { echo "Playing sound !\n"; sleep(1); if (!win_play_wav(NULL)) { echo "Unable to stop playing sound !\n"; } else { echo "Play stopped !\n"; } } /* Reg exemple */ $strMainKey = 'Control Panel'; $mainKey = reg_open_key(HKEY_CURRENT_USER, $strMainKey); if (!$mainKey) { err("Can't open '{$strMainKey}' !"); } echo "'{$strMainKey}' Key opened\n\nKeys:\n"; print_r(reg_enum_key($mainKey)); for ($i = 0; $key = reg_enum_key($mainKey, $i); $i++) { echo "\t{$key}\n"; } echo "\nValues:\n"; print_r(reg_enum_value($mainKey)); for ($i = 0; $value = reg_enum_value($mainKey, $i); $i++) { echo "\t{$value}=" . reg_get_value($mainKey, $value) . "\n"; } reg_close_key($mainKey); /* Res exemple */