[英]Vb.net wild cards in registry path
I want to read a registry value which resides in: 我想读取一个驻留在其中的注册表值:
HKEY_LOCAL_MACHINE\SOFTWARE\MyProgram\PROG7.0.0\Info
The value name is " Information " but the key " PROG7.0.0 " may have a variable name like " PROG7.2.111 ", changing the path to: 值名称为“ Information ”,但键“ PROG7.0.0 ”的变量名称可能类似于“ PROG7.2.111 ”,将路径更改为:
HKEY_LOCAL_MACHINE\SOFTWARE\MyProgram\PROG7.2.111\Info
The variable name will always be of the form " PROG7.xx.xxx ", where x is an integer. 变量名称将始终采用“ PROG7.xx.xxx ”的形式,其中x为整数。 Also, there will always be exactly one subkey of such name in
HKEY_LOCAL_MACHINE\\SOFTWARE\\MyProgram
另外,在
HKEY_LOCAL_MACHINE\\SOFTWARE\\MyProgram
,始终只有这样一个名称的子项
I know i can use Regestry.GetValue
method for reading a registry value but in my case the path is a variable - how can i go about it? 我知道我可以使用
Regestry.GetValue
方法读取注册表值,但是在我的情况下,路径是变量-我该如何处理?
Thanks a lot! 非常感谢!
using System;
using Microsoft.Win32;
namespace RegistryLister {
public static class Program {
static void Main(string[] args) {
//var key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\MyProgram\");
var key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\");
if (key != null)
foreach (var keyName in key.GetSubKeyNames()) {
//if (keyName.StartsWith("PROG7"))
if (keyName.StartsWith("Mic"))
Console.WriteLine(keyName);
}
Console.ReadKey();
/* Outputs:
*
* Microsoft
* Microsoft Corporation
*
*/
}
}
}
Read more about RegistryKey 阅读有关RegistryKey的更多信息
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.