今天著急改天補詳細用法
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;
}