Implementation Method: use the registry class provided by Microsoft. Win32 to access the system registry to obtain the ODBC Data Service list.
Specific implementation:
Microsoft. Win32 provides the registrykey class to access the registry of the system.
/// Define the registry sub-Path
String strregpath = @ "SOFTWARE \ ODBC. ini \ ODBC Data Sources ";
/// Create two registrykey classes. One Class points to the root path and the other class points to the sub-path.
Registrykey regrootkey;
Registrykey regsubkey;
/// Define root to point to the Registry HKEY_LOCAL_MACHINE Node
Regrootkey = registry. localmachine;
/// The registry enumeration class provides the following types
/*
Registry. classesroot --------------> points to the hkey_classes_root node of the Registry.
Registry. currentconfig --------------> points to the hkey_current_config node of the Registry.
Registry. currentuser --------------> points to the Registry HKEY_CURRENT_USER Node
Registry. dyndata --------------> points to the hkey_dyn_data node of the Registry (Dynamic registry data)
Registry. localmachine --------------> points to the Registry HKEY_LOCAL_MACHINE Node
Registry. performancedata --------------> points to the Registry hkey_performance_data Node
Registry. Users --------------> points to the HKEY_USERS node of the Registry.
*/
Regsubkey = regrootkey. opensubkey (strregpath );
String [] strdsnlist = regsubkey. getvaluenames ();
/// Close
Regsubkey. Close ();
Regrootkey. Close ();
In this way, the reading of the DSN service list is realized.