我想列出所有使用c#的用户数据源,但我无法做到这一点,因为我没有读取注册表项的权限。我如何获取所有用户数据源?注册表读取权限
我想下面的代码,但没有用
private List<string> ENUMDSN()
{
List<string> list = new List<string>();
list.AddRange(ENUMDSN(Registry.CurrentUser));
list.AddRange(ENUMDSN(Registry.LocalMachine));
XElement xmlele = new XElement("list", list.Select(i => new XElement("list", i)));
return list;
}
private IEnumerable<string> ENUMDSN(RegistryKey rootkey)
{
RegistryKey regkey = rootkey.OpenSubKey(@"Software\ODBC\ODBC.INI\ODBC Data Sources");
foreach (string name in regkey.GetValueNames())
{
string value = regkey.GetValue(name, "").ToString();
yield return name;
}
}
您是否尝试过使用提升的权限运行此代码?以管理员身份运行Visual Studio。 – Marco
也许这个主题将有助于:http://stackoverflow.com/questions/562016/listing-odbc-data-sources-in-c-sharp – psantos
什么说的例外? – i486