从.NET的ODBC驱动程序列表 [英] ODBC Driver List from .NET
问题描述
有没有办法让那些安装了.NET中的Windows XP计算机上的ODBC驱动程序的列表?
我基本上希望看到(在.NET)是什么:
控制面板 - >管理 工具 - >数据源(ODBC) - >驱动程序 标签。
请参阅这或<一href="http://www.devtoolshed.com/content/get-list-odbc-data-source-names-programatically-using-c">this
系统基本上这里存储了ODBC驱动程序的信息
HKEY_LOCAL_MACHINE \ SOFTWARE \ ODBC \ ODBCINST.INI \ ODBC驱动程序
您可以使用此或类似code,找出所安装的ODBC驱动程序。这code基本上读取注册表中的驱动程序信息
公共静态列表&LT;字符串&GT; GetSystemDriverList()
{
名单&LT;字符串&GT;名称=新的名单,其中,串&GT;();
//获取系统DSN的
Microsoft.Win32.RegistryKey章=(Microsoft.Win32.Registry.LocalMachine).OpenSubKey(软件);
如果(REG!= NULL)
{
章= reg.OpenSubKey(ODBC);
如果(REG!= NULL)
{
章= reg.OpenSubKey(ODBCINST.INI);
如果(REG!= NULL)
{
章= reg.OpenSubKey(ODBC驱动程序);
如果(REG!= NULL)
{
//获取DSN_LOC_IN_REGISTRY定义的所有DSN条目。
的foreach(字符串SNAME在reg.GetValueNames())
{
names.Add(SNAME);
}
}
尝试
{
reg.Close();
}
抓{/ *忽略此异常,如果我们不能关闭* /}
}
}
}
返回名称;
}
Is there a way to get a list of ODBC drivers that are installed on a Windows XP machine from .NET?
I basically would like to see (in .NET) what is in:
Control Panel->Administrative Tools->Data Sources (ODBC)->"Drivers" Tab.
Basically system stores the ODBC Driver's information here
HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBCINST.INI\ODBC Drivers
You can use this or similar code to find out the installed ODBC Drivers. This code basically reads the drivers info from registry
public static List<String> GetSystemDriverList()
{
List<string> names = new List<string>();
// get system dsn's
Microsoft.Win32.RegistryKey reg = (Microsoft.Win32.Registry.LocalMachine).OpenSubKey("Software");
if (reg != null)
{
reg = reg.OpenSubKey("ODBC");
if (reg != null)
{
reg = reg.OpenSubKey("ODBCINST.INI");
if (reg != null)
{
reg = reg.OpenSubKey("ODBC Drivers");
if (reg != null)
{
// Get all DSN entries defined in DSN_LOC_IN_REGISTRY.
foreach (string sName in reg.GetValueNames())
{
names.Add(sName);
}
}
try
{
reg.Close();
}
catch { /* ignore this exception if we couldn't close */ }
}
}
}
return names;
}
这篇关于从.NET的ODBC驱动程序列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!