从查询中读取前1个注册表值 [英] Read top 1 registry value from query
本文介绍了从查询中读取前1个注册表值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好我有多个注册表项都以相同的前缀开头,但我只想获取第一条记录,以便我可以阅读EventMessageFile详细信息。到目前为止,我有这个给了我一些记录:
Hi I have multiple registry entries all beginning with the same prefix but I only want to get the first record so I can read the EventMessageFile Details. So far I have this which gives me a count of the records:
int count = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"SYSTEM\\CurrentControlSet\\Services\\EventLog\\Application\\").GetSubKeyNames().Where(s => s.StartsWith("CardSpace")).Count();
如何选择第一条记录来阅读详细信息?
how do I select the first record to read the details?
推荐答案
你必须使用:
You have to use:
Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"SYSTEM\\CurrentControlSet\\Services\\EventLog\\Application\\").GetSubKeyNames().Where(s => s.StartsWith("CardSpace")).FirstOrDefault();
感谢你们两个人我最终得到了这个:
Thanks to both you guys I've ended up with this:
string servicename = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"SYSTEM\\CurrentControlSet\\Services\\EventLog\\Application\\").GetSubKeyNames().Where(s => s.StartsWith("CardSpace")).FirstOrDefault();
string dotNetFourPath = "SYSTEM\\CurrentControlSet\\Services\\EventLog\\Application\\" + servicename; // "AllstateCTSNGMedbillEP"; //servicename here
using (RegistryKey registryKey = Registry.LocalMachine.OpenSubKey(dotNetFourPath))
{
Console.WriteLine(registryKey.GetValue("EventMessageFile")); //returns EventMessageFile - Value Data
string sDt = registryKey.GetValue("EventMessageFile").ToString();
//sDt.Split('\\');
string[] sVar = sDt.Split('\\');
string sYourValue = sVar[4];
Console.WriteLine(sVar[0]);
Console.WriteLine(sVar[1]);
Console.WriteLine(sVar[2]);
Console.WriteLine(sVar[3]);
Console.WriteLine(sVar[4]);
Console.WriteLine(sVar[5]);
Console.WriteLine(sYourValue);
}
这篇关于从查询中读取前1个注册表值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文