如何检查注册表C#中是否存在字符串路径 [英] How to check if a string path exist in the registry C#
本文介绍了如何检查注册表C#中是否存在字符串路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好!
我有一本字典< sting,string>我存储密钥及其路径的地方,我想
检查注册表中是否已存在这些路径,这是我的字典:
Hi everyone !
I have a dictionary <sting,string> where i store keys and their paths and i want to
check if those paths exist already in the registry, that's my dictionary :
<pre> public static Dictionary<string, string> AllRegKeys = new Dictionary<string, string>()
{
{"clientId", "MyApp\\credentials\\Identif"},
{"clientSecret", "MyApp\\credentials\\Identif"},
{"Key 1", "MyApp\\credentials\\Identif"},
{"key 2 ", "MyApp\\credentials\\Identif"},
{"using link ", "MyApp\\credentials\\Folder"},
{"category", "MyApp\\credentials\\Hub\\Cat"},
{"link1", "MyApp\\credentials\\Settings\\link"},
{"link2", "MyApp\\credentials\\Settings\\link"},
{"link3", "MyApp\\credentials\\Settings\\link"},
};
我尝试过:
我试图在字典上循环并尝试比较值和注册表中存在的路径但是我被困在这里:
What I have tried:
i've tried to loop on the dictionary and try to compare between the values and existant paths in the registry but i'm stuck in here :
foreach (KeyValuePair<string, string> entry in ConstantsField.AllRegKeys)
{
if(entry.Value== )
}
推荐答案
如果您想查看是否存在单个值,则不需要显式循环:
If you are looking to see if a single value exists you don't need an explicit loop:
if (AllRegKeys.Values.Contains("MyApp\\credentials\\Folder"))
{
Console.WriteLine("Exists");
}
如果您想从新值列表中获取已存在的值:
If you want the values that are already there from a list of "new" values:
Dictionary<string, string> AllRegKeys = new Dictionary<string, string>()
{
{"clientId", "MyApp\\credentials\\Identif"},
{"clientSecret", "MyApp\\credentials\\Identif"},
{"Key 1", "MyApp\\credentials\\Identif"},
{"key 2 ", "MyApp\\credentials\\Identif"},
{"using link ", "MyApp\\credentials\\Folder"},
{"category", "MyApp\\credentials\\Hub\\Cat"},
{"link1", "MyApp\\credentials\\Settings\\link"},
{"link2", "MyApp\\credentials\\Settings\\link"},
{"link3", "MyApp\\credentials\\Settings\\link"},
};
List<string> findThese = new List<string>() { "MyApp\\credentials\\Folder", "MyApp\\credentials\\Identifu", "MyApp\\credentials\\Settings\\link" };
List<string> existing = AllRegKeys.Values.Intersect(findThese).ToList();
这篇关于如何检查注册表C#中是否存在字符串路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文