<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Серый форум &mdash; JScript: удаление заданного раздела реестра вместе с подразделами]]></title>
	<link rel="self" href="https://forum.script-coding.com/extern.php?action=feed&amp;tid=6802&amp;type=atom" />
	<updated>2012-02-11T14:58:03Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.script-coding.com/viewtopic.php?id=6802</id>
		<entry>
			<title type="html"><![CDATA[JScript: удаление заданного раздела реестра вместе с подразделами]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=56687#p56687" />
			<content type="html"><![CDATA[<p>JS альтернатива <a href="http://forum.script-coding.com/viewtopic.php?id=3905">VBScript: удаление заданного раздела реестра вместе с подразделами</a></p><div class="codebox"><pre><code>// Удаление ключа реестра (включая все вложенные)
function RegDeleteKeys(strFullPath){
	function DeleteSubkeys (subKey){
		var oMethod = oReg.Methods_.Item(&quot;EnumKey&quot;);
		var oInParam = oMethod.InParameters.SpawnInstance_();
		oInParam.hDefKey = defKey;
		oInParam.sSubKeyName = subKey;
		var oOutParam = oReg.ExecMethod_(oMethod.Name, oInParam);
		if (oOutParam.sNames != null) {
			var aNames = oOutParam.sNames.toArray();
			for (var i=0, keyName; keyName = aNames[i++];) {
				DeleteSubkeys(subKey + &quot;\\&quot; + keyName);
			}
		}
		oReg.DeleteKey (defKey, subKey);
	}
	// ----------------------------------------------------------------
	var aKeyPath = strFullPath.match(/^([\w_]+)\\(.+)$/);
	if (!aKeyPath) return;
	var aRoot = {HKEY_LOCAL_MACHINE:  0x80000002, HKLM: 0x80000002
				,HKEY_USERS:          0x80000003, HKU:  0x80000003
				,HKEY_CURRENT_USER:   0x80000001, HKCU: 0x80000001
				,HKEY_CLASSES_ROOT:   0x80000000, HKCR: 0x80000000
				,HKEY_CURRENT_CONFIG: 0x80000005, HKCC: 0x80000005}
	var defKey = aRoot[aKeyPath[1]];
	if (!defKey) return;
	var oReg = GetObject(&quot;winmgmts:\\\\.\\root\\default:StdRegProv&quot;);
	DeleteSubkeys (aKeyPath[2]);
}</code></pre></div><p>В качестве параметра принимает удаляемый ключ (полностью, включая root). Например, так:</p><div class="codebox"><pre><code>RegDeleteKeys(&quot;HKCR\\xslfile\\shell\\Open\\ddeexec&quot;);
// или так:
RegDeleteKeys(&quot;HKEY_CURRENT_USER\\Console&quot;);
// не советую запускать эти примеры не поразмыслив хорошенько ;)</code></pre></div>]]></content>
			<author>
				<name><![CDATA[mozers]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=4112</uri>
			</author>
			<updated>2012-02-11T14:58:03Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=56687#p56687</id>
		</entry>
</feed>
