C#作为微软开发的编程语言,对于自家Windows的访问机制还是很健全的,这里分享一个读取注册表中键值的方法
using Microsoft.Win32;
public string GetRegistry()
{
//获取注册表某键
string path = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\OEMInformation";//路径 注意'\'为转义字符
RegistryKey key = Registry.LocalMachine.OpenSubKey(path);//打开LOCALMACHINE下的子键
if (key != null)
{
object model = key.GetValue("Model");
if (model != null)
{
return model.ToString();
}
else
{
Console.WriteLine("Model键不存在");
}
}
else
{
Console.WriteLine("OEMInformation键不存在");
}
}
有时候读取注册表的值会更加准确和方便,前提是你能找到其存储路径