exclui a chave do registro usando curingas

6

Espero encontrar uma maneira de excluir chaves de registro com base em curingas usando um arquivo de lote, em vez de escrever algum vbscript. Alguém tem um exemplo?

Sou forçado a prosseguir com a maravilhosa remoção manual do Office pela MS, conforme descrito aqui:

http://support.microsoft.com/kb/928218

Um exemplo do que estou tentando remover é:

HKEY_CLASSES_ROOT\Installer\Products\*F01FEC HKEY_CLASSES_ROOT\Installer\UpgradeCodes\*F01FEC HKEY_CLASSES_ROOT\Installer\Win32Assemblies\*Office12*

A consulta reg poderia lançar os valores em uma variável e, possivelmente, atingi-los com um loop for?

FOR %%i IN (%PATH1% %PATH2% %PATH3%) DO (   
    reg delete %PATH1% /f
)
    
por Dennis Williamson 02.09.2009 / 15:09

2 respostas

4

Eu quebrei e escrevi um vbscript para a limpeza do registro que parece funcionar ...

On Error Resume Next
const HKEY_LOCAL_MACHINE = &H80000002
const HKEY_CLASSES_ROOT = &H80000000
const HKEY_CURRENT_USER = &H80000001
strComputer = "."

Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\" &_ 
strComputer & "\root\default:StdRegProv")

strKeyPath = "Software\Microsoft\Office.0"
DeleteSubkeys HKEY_CURRENT_USER, strKeyPath

strKeyPath = "Software\Microsoft\Office.0"
DeleteSubkeys HKEY_LOCAL_MACHINE, strKeyPath

strKeyPath = "SYSTEM\CurrentControlSet\Services\ose"
Deletesubkeys HKEY_LOCAL_MACHINE, strKeyPath

strKeyPath = "SOFTWARE\Microsoft\Office\Delivery\SourceEngine\Downloads"
oReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys
For Each subkey In arrSubKeys
    If Not InStr(subkey, "0FF1CE}-") = 0 Then
        'WScript.Echo subkey
    Deletesubkeys HKEY_LOCAL_MACHINE, strKeyPath & "\" & subkey
    End If
Next

strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
oReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys
For Each subkey In arrSubKeys
    If Not InStr(subkey, "0FF1CE") = 0 Then
        'WScript.Echo subkey
    Deletesubkeys HKEY_LOCAL_MACHINE, strKeyPath & "\" & subkey
    End If
Next

strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UpgradeCodes"
oReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys

For Each subkey In arrSubKeys
    If Not InStr(subkey, "F01FEC") = 0 Then
        'WScript.Echo subkey
    Deletesubkeys HKEY_LOCAL_MACHINE, strKeyPath & "\" & subkey
    End If
Next

strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products"
oReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys
For Each subkey In arrSubKeys
    If Not InStr(subkey, "F01FEC") = 0 Then
        'WScript.Echo subkey
    Deletesubkeys HKEY_LOCAL_MACHINE, strKeyPath & "\" & subkey
    End If
Next

strKeyPath = "Installer\Features"
oReg.EnumKey HKEY_CLASSES_ROOT, strKeyPath, arrSubKeys
For Each subkey In arrSubKeys
    If Not InStr(subkey, "F01FEC") = 0 Then
        'WScript.Echo subkey
    Deletesubkeys HKEY_CLASSES_ROOT, strKeyPath & "\" & subkey
    End If
Next

strKeyPath = "Installer\Products"
oReg.EnumKey HKEY_CLASSES_ROOT, strKeyPath, arrSubKeys
For Each subkey In arrSubKeys
    If Not InStr(subkey, "F01FEC") = 0 Then
        'WScript.Echo subkey
    Deletesubkeys HKEY_CLASSES_ROOT, strKeyPath & "\" & subkey
    End If
Next

strKeyPath = "Installer\UpgradeCodes"
oReg.EnumKey HKEY_CLASSES_ROOT, strKeyPath, arrSubKeys
For Each subkey In arrSubKeys
    If Not InStr(subkey, "F01FEC") = 0 Then
        'WScript.Echo subkey
    Deletesubkeys HKEY_CLASSES_ROOT, strKeyPath & "\" & subkey
    End If
Next

strKeyPath = "Installer\Win32Assemblies"
oReg.EnumKey HKEY_CLASSES_ROOT, strKeyPath, arrSubKeys
For Each subkey In arrSubKeys
    If Not InStr(subkey, "Office12") = 0 Then
        'WScript.Echo subkey
    Deletesubkeys HKEY_CLASSES_ROOT, strKeyPath & "\" & subkey
    End If
Next

Sub DeleteSubkeys(reghive, KeyPath) 
    Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\" &_ 
strComputer & "\root\default:StdRegProv")
    objReg.EnumKey reghive, KeyPath, arrrSubkeys 

    If IsArray(arrrSubkeys) Then 
        For Each strrSubkey In arrrSubkeys 
            DeleteSubkeys reghive, KeyPath & "\" & strrSubkey 
        Next 
    End If 

    objReg.DeleteKey reghive, KeyPath 
End Sub
    
por 02.09.2009 / 17:12
2

Suponho que você use o REGEDIT e use FIND para rastejar pela lista (ou obtenha um port do GNU grep para o Win32 e use uma expressão regular). Você corre um pequeno risco de excluir as chaves do registro que não "pertencem" ao Office, já que um fragmento de um GUID não é globalmente exclusivo!

@echo off
set TEMPFILE=%TEMP%\%RANDOM%.REG
set TODELETE=%TEMP%\%RANDOM%.REG

regedit /e "%TEMPFILE%" HKEY_CLASSES_ROOT\Installer

find "HKEY_CLASSES_ROOT\Installer\Products" "%TEMPFILE%" | find "C]" > "%TODELETE%"
find "HKEY_CLASSES_ROOT\Installer\UpgradeCodes" "%TEMPFILE%" | find "C]" >> "%TODELETE%"
find "HKEY_CLASSES_ROOT\Installer\Win32Assemblies" "%TEMPFILE%" | find "C]" >> "%TODELETE%"

for /f "delims=[]" %%i in (%TODELETE%) do reg delete /f "%%i"

del "%TEMPFILE%"
del "%TODELETE%"
:end
    
por 02.09.2009 / 16:42