windows 如何在批处理或 VBScript 中使用通配符在注册表中搜索键?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7498252/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to search for a key in the registry with wildcards in a batch or VBScript?
提问by kampi
I need to make a batch or a VBScript, which uninstalls every versions of Mozilla Firefox. In the registry there is a key:
我需要制作一个批处理或 VBScript,它会卸载每个版本的 Mozilla Firefox。在注册表中有一个键:
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 :
Version
具有已安装的 Firefox 版本的值。在这个键下有一个条目UninstallString
。我需要以某种方式读取这个值。问题是,版本是一个变量。因此,如果 Mozilla Firefox 1.0.1 is nottalled 那么密钥将如下所示:
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:
如果安装了 2.0.2,那么密钥将如下所示:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Mozilla 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.
谢谢。
采纳答案by Alex K.
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)
Version:Mozilla Firefox 7.0 (x86 en-GB)
Uninstaller:C:\Program Files\Mozilla Firefox\uninstall\helper.exe
Uninstaller:C:\Program Files\Mozilla Firefox\uninstall\helper.exe
(Note this is different from your pattern)
(请注意,这与您的模式不同)