今天着急改天补详细用法
1)using Microsoft.Win32;这是常规的方法,有很多详细介绍,这不是重点
Code
public static string GetRegValue(string strRegpath, string strRegKeyName)
{
string str;
try
{
RegistryKey rk = Registry.LocalMachine.OpenSubKey(strRegpath, true);
if (rk != null)
{
str = rk.GetValue(strRegKeyName).ToString();
}
else
{
str = "Unable find the specified registry key or value";
}
}
catch (Exception e)
{
str = "Unable find the specified registry key or value,Vista May need close UAC ! " + e;
}
return str;
}
2)引用wshom.ocx:这提供了一条途径复用各种脚本,当framework提供的方法不好用时可以考虑。暂时只是觉得有用,还不知道怎么用,呵呵,atc那些乱七八糟的脚本都可以用了
var Reg = new ActiveXObject("WScript.Shell");//找到WScript.Shell所在的ocx引用之
Reg.read();
Code
public static string GetRegValue(string strRegPath)
{
string strRegValue;
try
{
IWshRuntimeLibrary.WshShell ws = new IWshRuntimeLibrary.WshShell();
strRegValue = ws.RegRead(strRegPath).ToString();
}
catch (Exception e)
{
strRegValue = "Unable find the specified registry key or value,Vista May need close UAC ! " + e;
}
return strRegValue;
}