在注册表中搜索密钥 - JScript
有没有办法使用 Windows 脚本主机在注册表中搜索特定密钥?
我使用 JavaScript (Jscript/VBScript?)来执行此操作,并且 msdn 库没有提及任何此类方法:http://msdn.microsoft.com/en-us/library/2x3w20xf(v=VS.85).aspx< /a>
谢谢,
所以这里是问题的更新:
这个问题比直接注册表搜索要复杂一些。我必须查看 Windows 盒子上已安装的产品,找到我想要删除的特定产品条目。注册表路径定义为:
HKEY_LOCAL_MACHINE\Software\Microsoft...\Products。
在产品密钥中,列出了已安装的产品,但它们的密钥定义为哈希码。产品密钥内还有具有定义名称和定义值的其他密钥。我希望能够搜索后面的键和值。我怎样才能做到这一点,绕过未知的哈希码?
例如,我需要查找 DisplayVersion key = 1.0.0 的产品。该密钥的路径为:
HKLM\Software\Microsoft\Windows\CurrentVersion\Installer\UserData\Products\A949EBE4EED5FD113A0CB40EED7D0258\InstallProperties\DisplayVersion。
我如何获取或避免写入产品密钥:A949EBE4EED5FD113A0CB40EED7D0258?
Is there a way to search the Registry for a specific key using Windows Scripting Host?
I'm using JavaScript (Jscript/VBScript?) to do so, and the msdn Library doesn't mention any such method: http://msdn.microsoft.com/en-us/library/2x3w20xf(v=VS.85).aspx
Thanks,
So here's an update to the problem:
The problem is a bit more complicated than a direct registry search. I have to look through the installed products on a windows box, to find a specific product entry that i want to delete. The registry path is defined as:
HKEY_LOCAL_MACHINE\Software\Microsoft...\Products.
Within the Products key, the installed products are listed, but their keys are defined as hash codes. Within the product keys are other keys with defined names and defined values. I want to be able to search on the latter keys and values. How can I do that, by-passing the unknown hash codes?
For example, I need to find a product with DisplayVersion key = 1.0.0. The path to that key is:
HKLM\Software\Microsoft\Windows\CurrentVersion\Installer\UserData\Products\A949EBE4EED5FD113A0CB40EED7D0258\InstallProperties\DisplayVersion.
How can I either pick up, or avoid writing, the product key: A949EBE4EED5FD113A0CB40EED7D0258 ??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
假设您通过 Windows 脚本主机使用 JScript(而不是来自浏览器的 JavaScript),您可以使用
WScript.RegRead
方法:如果您确实需要根据某些条件而不是某个值来搜索键或值如果已知注册表项,则您可以实现自己的递归搜索算法,其中“REG_SZ”类型的注册表值是叶节点。
作为更熟悉 Windows 脚本主机上的 JScript 的练习,我制作了一个注册表的小界面 正是这样做的。该项目中包含的示例展示了如何在 WSF 脚本中执行此类注册表搜索:
请注意,正如 @Robert Harvey 指出的那样,如果根键连接太深,这可能需要很长时间。对我选择的钥匙进行简单测试只需几秒钟,但您的里程可能会有所不同;当然,没有任何保证或适用性,如果您的计算机爆炸了,请不要责怪我。
Assuming you're using JScript via the Windows Scripting Host (and not JavaScript from a browser) you can get the value of a specific key using the
WScript.RegRead
method:If you actually need to search for a key or value based on some conditions rather than a known registry key then you can to implement your own recursive search algorithm where registry values of type "REG_SZ" are leaf nodes.
As an exercise to get more familiar with JScript on the Windows Scripting Host, I've made a small interface to the registry that does exactly this. The example included in the project shows how to perform such a registry search in a WSF script:
Note that, as @Robert Harvey points out, this could take a really long time if the root key is too deeply connected. Simple testing takes only a few seconds on the key I chose but your mileage may vary; of course, no warranty or fitness for a purpose, don't blame me if your computer blows up.
http://code.google.com/p/jslibs/
(如果您不这样做)在那里找到它,你必须自己实现它
http://code.google.com/p/jslibs/
if you don't find it there, you have to implement it yourself