使用VBS删除注册表文件夹和子文件夹

时间:2014-04-22 06:40:23

标签: vbscript

我想使用vb脚本删除其下的注册表文件夹和子文件夹。

在reg文件中我们可以编写如下脚本:

[-HKEY_LOCAL_MACHINE\SOFTWARE\abc\prr]

以上脚本将删除prr

下的子文件夹

如何使用VB脚本实现相同的目标?

我尝试使用 .RegDelete ,但我认为它仅适用于密钥而不适用于注册表文件夹。

感谢。

1 个答案:

答案 0 :(得分:0)

[path] RegDelete [Key] | [数值]

RegDelete的路径路径(因此Windows可以找到它)。请参阅Windows 98提示和黑客页面上的提示,以使Windows始终找到它。

Nothing使用用户界面启动RegDelete。键入要删除的键或值时,请勿在引号中包含键或值。

键删除的键。键总是以反斜杠结尾。如果键包含空格,则必须用引号括起来。密钥和子密钥将被删除。

值要删除的值。值没有尾部反斜杠。如果键包含空格,则必须用引号括起来。

将以下行复制到新文本文档中并另存为RegDelete.vbs。

'RegDelete.vbs
'Deletes keys or values from the registry.
'
'
On Error Resume Next
vbPara=vbCRLF & vbCRLF
strExplain="RegDelete deletes keys and values from the registry." & vbPara & "Keys must end with a backspace and values must not." & vbPara & "Start without parameters to type in a key or value to delete, or place the key or value on the command line (use inverted commas to surround the key or value if it contains spaces)."  & vbPara & "Continue"
strTitle="Reg Delete"
Key=""
Dim silent
Silent=""

Dim Sh
Set Sh = WScript.CreateObject("WScript.Shell")
ReportErrors "Creating Shell"

Key=GetKey()
If Key<>"" then 
    B=Sh.RegRead (Key)
    If Err.Number=0 Then 
        Sh.RegDelete Key
        If Err.Number =0 Then 
            If silent<>"yes" Then MsgBox Key & " deleted", vbOKOnly + vbInformation, strTitle
        Else
            ReportErrors "DeletingKey"
        End If
    Else
        If Err.Number=-2147024893 then 
            Err.Clear
            MsgBox Key & " didn't exist", vbOKOnly + vbCritical, strTitle
        Else
            ReportErrors "Reading before Deleting Key"
        End If
    End If
End If

ReportErrors "Main"

Function GetKey()
    Dim Ag
    Set Ag=Wscript.Arguments
    ReportErrors "Creating Aguments"
    If Ag.Count=1 then GetKey=Ag(0)
    Silent="yes"
    If Ag.Count >1 then sgBox "Too many parameters on command line. Try enclosing the key in a space",vbOKOnly + vbCritical, strTitle

    If Ag.Count=0 then 
        If MsgBox (strExplain, vbYesNo + vbInformation, strTitle)=6 Then
            GetKey=InputBox ("Enter the value or key to delete." & vbPara & "Keys must end in a backspace.", strTitle, strNamet1)
        End If
    End If
End Function

Sub ReportErrors(strModuleName)
    If err.number<>0 then Msgbox "Error occured in " & strModuleName & " module of " & err.number& " - " & err.description & " type" , vbCritical + vbOKOnly, "Something unexpected"
    Err.clear
End Sub
相关问题