<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[Серый форум &mdash; VBScript: удаление заданного раздела реестра вместе с подразделами]]></title>
		<link>https://forum.script-coding.com/viewtopic.php?id=3905</link>
		<atom:link href="https://forum.script-coding.com/extern.php?action=feed&amp;tid=3905&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[Недавние сообщения в теме «VBScript: удаление заданного раздела реестра вместе с подразделами».]]></description>
		<lastBuildDate>Sat, 21 Nov 2009 16:13:22 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[VBScript: удаление заданного раздела реестра вместе с подразделами]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=30928#p30928</link>
			<description><![CDATA[<p>Используется WMI провайдер «StdRegProv» и рекурсивный перебор вложенных подразделов с последующим их удалением. Результат выполнения функции «DeleteRegistryKey()» определяется группой констант «con_*» («0» — успешное удаление).<br /></p><div class="codebox"><pre><code>&#039; Объявляется глобально (рекомендуется), либо на уровне RecursiveRegKeyDelete
Set objReg = GetObject(&quot;winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv&quot;)

&#039; Пример вызова
Result = DeleteRegistryKey(&quot;HKLM\SOFTWARE\SOMETHING&quot;)

WScript.Echo &quot;Result:&quot;, Result

Set objReg = Nothing
&#039;---------------------------------------------------------
Function DeleteRegistryKey(parKey)
    &#039;On Error Resume Next
    
    Const HKEY_CLASSES_ROOT   = &amp;H80000000
    Const HKEY_CURRENT_USER   = &amp;H80000001
    Const HKEY_LOCAL_MACHINE  = &amp;H80000002
    Const HKEY_CURRENT_CONFIG = &amp;H80000005
    
    Select Case Left(parKey,4)
        Case &quot;HKLM&quot;: lngRoot = HKEY_LOCAL_MACHINE
        Case &quot;HKCU&quot;: lngRoot = HKEY_CURRENT_USER
        Case &quot;HKCR&quot;: lngRoot = HKEY_CLASSES_ROOT
        Case &quot;HKCC&quot;: lngRoot = HKEY_CURRENT_CONFIG
    End Select 
    
    intResult = RecursiveRegKeyDelete(lngRoot, Mid(parKey, 6))
    
    DeleteRegistryKey = intResult
End Function

&#039;-------------------------------------------------    

Function RecursiveRegKeyDelete(parRoot, parKey)
    &#039;On Error Resume Next
    
    Const con_READ_CONTROL           = 131072
    Const con_KeyDeletedSuccessfully = 0
    Const con_KeyDoesNotExist        = 1
    Const con_AccessDenied           = 2 &#039; либо нет доступа, либо не удалось удалить вложенные ключи
    Const con_SomeOtherError         = 3
    
    
    If objReg.CheckAccess(parRoot,parKey,con_READ_CONTROL) = 0 Then
        If objReg.EnumKey(parRoot, parKey, arrSubKeys) = 0 Then
            If Not IsNull(arrSubKeys) Then
                For i = 0 To UBound(arrSubKeys)
                    RecursiveRegKeyDelete parRoot, parKey &amp; &quot;\&quot; &amp; arrSubKeys(i)
                Next
            End If
        End If
        
        intResult = objReg.DeleteKey(parRoot, parKey)
        
        If intResult = 0 Then 
            RecursiveRegKeyDelete = con_KeyDeletedSuccessfully
        ElseIf intResult = 5 Then
            RecursiveRegKeyDelete = con_AccessDenied
        Else
            RecursiveRegKeyDelete = Con_SomeOtherError
        End If
    Else
        RecursiveRegKeyDelete = con_KeyDoesNotExist
    End If
End Function
&#039;-------------------------------------------------</code></pre></div><p>Автор идеи — <strong>dsb</strong>.</p>]]></description>
			<author><![CDATA[null@example.com (alexii)]]></author>
			<pubDate>Sat, 21 Nov 2009 16:13:22 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=30928#p30928</guid>
		</item>
	</channel>
</rss>
