Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Search 在注册表中搜索多个值_Search_Vbscript_Registry - Fatal编程技术网

Search 在注册表中搜索多个值

Search 在注册表中搜索多个值,search,vbscript,registry,Search,Vbscript,Registry,我想知道如何使用.vbs脚本搜索注册表中的多个条目,例如下面的条目,然后在找到时发出警报并删除 HKLM\SOFTWARE\Classes\Interface\{03E2A1F3-4402-4121-8B35-733216D61244} HKLM\SOFTWARE\Classes\Interface\{03E2A1F3-4402-4121-8B35-733216D61296} HKLM\SOFTWARE\Classes\Interface\{03E2A1F3-4402-4121-8B35-733

我想知道如何使用.vbs脚本搜索注册表中的多个条目,例如下面的条目,然后在找到时发出警报并删除

HKLM\SOFTWARE\Classes\Interface\{03E2A1F3-4402-4121-8B35-733216D61244}
HKLM\SOFTWARE\Classes\Interface\{03E2A1F3-4402-4121-8B35-733216D61296}
HKLM\SOFTWARE\Classes\Interface\{03E2A1F3-4402-4121-8B35-733216D61211}
HKLM\SOFTWARE\Classes\Interface\{03E2A1F3-4402-4121-8B35-733216D61290}
HKEY_LOCAL_MACHINE\software\classes\look.rean\test

删除这些密钥的最简单方法是:


这是一个更一般的声明,而不是针对OP-请小心注册表

'Registry Search and Destroy
'---------------------------
'Place Registry Keys Here...
'---------------------------
Dim RegSAndRKEYS(4)
RegSAndRKEYS(0) = "HKLM\SOFTWARE\Classes\Interface\{03E2A1F3-4402-4121-8B35-733216D61244}"
RegSAndRKEYS(1) = "HKLM\SOFTWARE\Classes\Interface\{03E2A1F3-4402-4121-8B35-733216D61296}"
RegSAndRKEYS(2) = "HKLM\SOFTWARE\Classes\Interface\{03E2A1F3-4402-4121-8B35-733216D61211}"
RegSAndRKEYS(3) = "HKLM\SOFTWARE\Classes\Interface\{03E2A1F3-4402-4121-8B35-733216D61290}"
RegSAndRKEYS(4) = "HKLM\software\classes\look.rean\test"


'----------------------Code--------------------
Const HKEY_LOCAL_MACHINE = &H80000002
Const HKEY_CURRENT_USER = &H80000001
Dim aSub, sKey, aSubToo, sKeyToo, dwValue, FoundKey, keypass
Dim oReg,arrSubKeys,strSubkey,reg : Set oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")
Dim oShell : Set oShell = CreateObject("WScript.Shell")
dim return_text

For reg=0 To UBound(RegSAndRKEYS)
    Dim tmp,op,i : tmp = Split(RegSAndRKEYS(reg), "\")
        op = ""
    For i=1 To UBound(tmp)-1
        If Len(op) = 0 Then
            op = tmp(i)
        Else
            op = op & "\" & tmp(i)
        End If
    Next
    If tmp(0) = "HKLM" Then
        RegSAndRKEYS(reg) = RegSearchAndDestroy(HKEY_LOCAL_MACHINE, op, tmp(UBound(tmp)))
    ElseIf tmp(0) = "HKCU" Then
        RegSAndRKEYS(reg) = RegSearchAndDestroy(HKEY_CURRENT_USER, op, tmp(UBound(tmp)))
    End If
    'Echo Results
    WScript.echo RegSAndRKEYS(reg)
Next

Function RegSearchAndDestroy(HOSTREG, sPath, Key2Find)
    ' Get all keys within sPath
    oReg.EnumKey HOSTREG, sPath, aSub

    FoundKey = False
    ' Loop through each key
    For Each sKey In aSub
        If sKey = Key2Find Then
            keypass = sPath & "\" & sKey
            FoundKey = True
            Exit For
        End If

        On Error Resume Next
        oReg.EnumKey HOSTREG, sPath & "\" & sKey, aSubToo
        If Err.number <> 0 Then 
            Err.clear
        Else
            For Each sKeyToo In aSubToo
                If sKeyToo = Key2Find Then
                    keypass = sPath & "\" & sKey & "\" & sKeyToo
                    FoundKey = True
                    Exit For
                End If
            Next
        End If
    Next
    If FoundKey Then
        DeleteSubkeys HOSTREG, keypass
        RegSearchAndDestroy = return_text
    Else
        return_text = "Key Not Found!"
        RegSearchAndDestroy = return_text
    End If

End Function

Function DeleteSubkeys(HOSTREGISTRY, strKeyPath)
    oReg.EnumKey HOSTREGISTRY, strKeyPath, arrSubkeys 
    If IsArray(arrSubkeys) Then 
        For Each strSubkey In arrSubkeys
            DeleteSubkeys HOSTREGISTRY, strKeyPath & "\" & strSubkey
        Next
    End If
    intAnswer = MsgBox("Are you sure you want to delete this registry key?" & vbCrLf & strKeyPath, vbYesNo, "Delete Registry Keys")
    If intAnswer = vbYes Then
        Return = oReg.DeleteKey(HOSTREGISTRY, strKeyPath)
        If (Return = 0) And (Err.Number = 0) Then    
            return_text = strKeyPath & " successfully deleted!"
        Else
            return_text = "DeleteKey failed. Error = " & Err.Number
        End If
    else
        return_text = "User Opted Out" 
    End If
End Function
“注册表搜索和销毁”
'---------------------------
'在此处放置注册表项。。。
'---------------------------
调校和调校(4)
RegSAndRKEYS(0)=“HKLM\SOFTWARE\Classes\Interface\{03E2A1F3-4402-4121-8B35-733216D61244}”
RegSAndRKEYS(1)=“HKLM\软件\类\接口\{03E2A1F3-4402-4121-8B35-733216D61296}”
RegSAndRKEYS(2)=“HKLM\SOFTWARE\Classes\Interface\{03E2A1F3-4402-4121-8B35-733216D61211}”
RegSAndRKEYS(3)=“HKLM\软件\类\接口\{03E2A1F3-4402-4121-8B35-733216D61290}”
RegSAndRKEYS(4)=“HKLM\software\classes\look.rean\test”
“-------------------------代码--------------------
Const HKEY_本地_机器=&H8000002
Const HKEY_当前用户=&H80000001
尺寸aSub、sKey、aSubToo、sKeyToo、dwValue、FoundKey、keypass
Dim-oReg,arrsubkey,strSubkey,reg:Set-oReg=GetObject(“winmgmts:{impersonationLevel=impersonate}\\.\root\default:StdRegProv”)
Dim oShell:Set oShell=CreateObject(“WScript.Shell”)
返回文本变暗
对于reg=0到UBound(RegSAndRKEYS)
Dim tmp,op,i:tmp=Split(RegSAndRKEYS(reg),“\”)
op=“”
对于i=1至UBound(tmp)-1
如果Len(op)=0,则
op=tmp(一)
其他的
op=op&“\”&tmp(一)
如果结束
下一个
如果tmp(0)=“HKLM”,则
RegSAndRKEYS(reg)=RegSearchAndDestroy(HKEY_本地_机器,op,tmp(UBound(tmp)))
否则tmp(0)=“HKCU”则
RegSAndRKEYS(reg)=RegSearchAndDestroy(HKEY_当前_用户、op、tmp(UBound(tmp)))
如果结束
“回音结果
WScript.echo RegSAndRKEYS(reg)
下一个
函数RegSearchAndDestroy(HOSTREG、sPath、Key2Find)
“在斯帕斯内拿到所有钥匙
oReg.EnumKey HOSTREG、sPath、aSub
FoundKey=False
'循环通过每个键
对于aSub中的每个sKey
如果sKey=Key2Find,则
keypass=sPath&“\”sKey
FoundKey=True
退出
如果结束
出错时继续下一步
oReg.EnumKey HOSTREG,sPath&“\”和sKey,aSubToo
如果错误号为0,则
清楚
其他的
对于aSubToo中的每个sKeyToo
如果sKeyToo=Key2Find,则
keypass=sPath&“\”&sKey&“\”&sKeyToo
FoundKey=True
退出
如果结束
下一个
如果结束
下一个
如果找到钥匙,那么
删除子密钥HOSTREG,密钥传递
RegSearchAndDestroy=返回\u文本
其他的
return\u text=“找不到密钥!”
RegSearchAndDestroy=返回\u文本
如果结束
端函数
函数DeleteSubkeys(主机注册表,strKeyPath)
oReg.EnumKey主机注册表、strKeyPath、arrsubkey
如果是IsArray(arrsubkey),则
对于ArrSubkey中的每个strSubkey
删除主机注册表中的子项,strKeyPath&“\”&strSubkey
下一个
如果结束
intAnswer=MsgBox(“是否确实要删除此注册表项?”&vbCrLf&strKeyPath,vbYesNo,“删除注册表项”)
如果intAnswer=vbYes,则
Return=oReg.DeleteKey(主机注册表,strKeyPath)
如果(Return=0)和(Err.Number=0),则
return\u text=strKeyPath&“已成功删除!”
其他的
return_text=“DeleteKey失败。Error=“&Err.Number
如果结束
其他的
return\u text=“用户选择退出”
如果结束
端函数

非常感谢。很抱歉提出这些问题,但是如果我想在扫描完成后而不是每次搜索后提醒用户,我该如何实现这一点?再次感谢您的意见,谢谢
'Registry Search and Destroy
'---------------------------
'Place Registry Keys Here...
'---------------------------
Dim RegSAndRKEYS(4)
RegSAndRKEYS(0) = "HKLM\SOFTWARE\Classes\Interface\{03E2A1F3-4402-4121-8B35-733216D61244}"
RegSAndRKEYS(1) = "HKLM\SOFTWARE\Classes\Interface\{03E2A1F3-4402-4121-8B35-733216D61296}"
RegSAndRKEYS(2) = "HKLM\SOFTWARE\Classes\Interface\{03E2A1F3-4402-4121-8B35-733216D61211}"
RegSAndRKEYS(3) = "HKLM\SOFTWARE\Classes\Interface\{03E2A1F3-4402-4121-8B35-733216D61290}"
RegSAndRKEYS(4) = "HKLM\software\classes\look.rean\test"


'----------------------Code--------------------
Const HKEY_LOCAL_MACHINE = &H80000002
Const HKEY_CURRENT_USER = &H80000001
Dim aSub, sKey, aSubToo, sKeyToo, dwValue, FoundKey, keypass
Dim oReg,arrSubKeys,strSubkey,reg : Set oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")
Dim oShell : Set oShell = CreateObject("WScript.Shell")
dim return_text

For reg=0 To UBound(RegSAndRKEYS)
    Dim tmp,op,i : tmp = Split(RegSAndRKEYS(reg), "\")
        op = ""
    For i=1 To UBound(tmp)-1
        If Len(op) = 0 Then
            op = tmp(i)
        Else
            op = op & "\" & tmp(i)
        End If
    Next
    If tmp(0) = "HKLM" Then
        RegSAndRKEYS(reg) = RegSearchAndDestroy(HKEY_LOCAL_MACHINE, op, tmp(UBound(tmp)))
    ElseIf tmp(0) = "HKCU" Then
        RegSAndRKEYS(reg) = RegSearchAndDestroy(HKEY_CURRENT_USER, op, tmp(UBound(tmp)))
    End If
    'Echo Results
    WScript.echo RegSAndRKEYS(reg)
Next

Function RegSearchAndDestroy(HOSTREG, sPath, Key2Find)
    ' Get all keys within sPath
    oReg.EnumKey HOSTREG, sPath, aSub

    FoundKey = False
    ' Loop through each key
    For Each sKey In aSub
        If sKey = Key2Find Then
            keypass = sPath & "\" & sKey
            FoundKey = True
            Exit For
        End If

        On Error Resume Next
        oReg.EnumKey HOSTREG, sPath & "\" & sKey, aSubToo
        If Err.number <> 0 Then 
            Err.clear
        Else
            For Each sKeyToo In aSubToo
                If sKeyToo = Key2Find Then
                    keypass = sPath & "\" & sKey & "\" & sKeyToo
                    FoundKey = True
                    Exit For
                End If
            Next
        End If
    Next
    If FoundKey Then
        DeleteSubkeys HOSTREG, keypass
        RegSearchAndDestroy = return_text
    Else
        return_text = "Key Not Found!"
        RegSearchAndDestroy = return_text
    End If

End Function

Function DeleteSubkeys(HOSTREGISTRY, strKeyPath)
    oReg.EnumKey HOSTREGISTRY, strKeyPath, arrSubkeys 
    If IsArray(arrSubkeys) Then 
        For Each strSubkey In arrSubkeys
            DeleteSubkeys HOSTREGISTRY, strKeyPath & "\" & strSubkey
        Next
    End If
    intAnswer = MsgBox("Are you sure you want to delete this registry key?" & vbCrLf & strKeyPath, vbYesNo, "Delete Registry Keys")
    If intAnswer = vbYes Then
        Return = oReg.DeleteKey(HOSTREGISTRY, strKeyPath)
        If (Return = 0) And (Err.Number = 0) Then    
            return_text = strKeyPath & " successfully deleted!"
        Else
            return_text = "DeleteKey failed. Error = " & Err.Number
        End If
    else
        return_text = "User Opted Out" 
    End If
End Function