6 scripting windows batch windows-registry
我希望找到一种使用批处理文件而不是编写一些 vbscript 来删除基于通配符的注册表项的方法。有人有例子吗?
我被迫继续进行 MS 出色的手动删除 Office,如下所述:
我试图删除的一个例子是:
HKEY_CLASSES_ROOT\Installer\Products\*F01FEC HKEY_CLASSES_ROOT\Installer\UpgradeCodes\*F01FEC HKEY_CLASSES_ROOT\Installer\Win32Assemblies\*Office12*
reg 查询能否将值扔到一个变量中,然后可能用 for 循环命中它们?
FOR %%i IN (%PATH1% %PATH2% %PATH3%) DO (
reg delete %PATH1% /f
)
Run Code Online (Sandbox Code Playgroud)
小智 5
我崩溃了,写了一个用于注册表清理的 vbscript,这似乎有效......
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\12.0"
DeleteSubkeys HKEY_CURRENT_USER, strKeyPath
strKeyPath = "Software\Microsoft\Office\12.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
Run Code Online (Sandbox Code Playgroud)
I suppose you use REGEDIT and then use FIND to grovel thru the list (or get a port of GNU grep for Win32 and serach using a regular expression). You do run a slight risk of deleting registry keys that don't "belong" to Office, since a fragment of a GUID isn't globally unique!
@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
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
13132 次 |
| 最近记录: |