How to search for a key in the registry with wildcards in a batch or VBScript?
I need to make a batch or a VBScript, which uninstalls every versions of Mozilla Firefox. In the registry there is a key:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Mozilla Firefox (Version).
Version
has a value the installed Firefox Versions. And under this key there is an entry UninstallString
. I need read somehow this value. The problem is, that the Version is a variable. So if Mozilla Firefox 1.0.1 is isntalled then the key will look like :
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Mozilla Firefox (1.0.1).
If 2.0.2 is installed, then the key will look like:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Mozilla开发者_如何学Python Firefox (2.0.2).
But i don't know which version is installed. So how can i read this key (and the Uninstall value) without knowing which version is installed? Could someone help me in this?
Thanks.
How about:
const HKEY_LOCAL_MACHINE = &H80000002
const REG_PATH = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"
const FOX_MASK = "Mozilla Firefox*"
dim re: set re = New RegExp
re.IgnoreCase = True
re.Global = True
re.Pattern = FOX_MASK
dim oReg: set oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")
oReg.EnumKey HKEY_LOCAL_MACHINE, REG_PATH, arrSubKeys
dim strValue
for each subkey In arrSubKeys
if re.test(subkey) then
oReg.GetExpandedStringValue HKEY_LOCAL_MACHINE, REG_PATH & subkey, "UninstallString", strValue
WScript.StdOut.WriteLine "Version: " & subkey
WScript.StdOut.WriteLine "Uninstaller: " & strValue
end if
next
For me outputs:
Version: Mozilla Firefox 7.0 (x86 en-GB)
Uninstaller: C:\Program Files\Mozilla Firefox\uninstall\helper.exe
(Note this is different from your pattern)
精彩评论