實現方式:利用microsoft.win32類提供的注冊表類訪問系統注冊表獲取odbc數據服務列表。
具體實現:
    microsoft.win32提供了registrykey類,用來訪問系統的注冊表。
    ///定義注冊表子path
    string strregpath = @"software/odbc/odbc.ini/odbc data sources";
    ///創建兩個registrykey類,一個將指向root path,另一個將指向子path
    registrykey regrootkey;
    registrykey regsubkey;
    ///定義root指向注冊表hkey_local_machine節點
    regrootkey = registry.localmachine;
    ///registry枚舉類提供了以下幾種
    /*
    registry.classesroot-------------->指向注冊表hkey_classes_root節點
    registry.currentconfig-------------->指向注冊表hkey_current_config節點
    registry.currentuser-------------->指向注冊表hkey_current_user節點
    registry.dyndata-------------->指向注冊表hkey_dyn_data節點(動態注冊表數據)
    registry.localmachine-------------->指向注冊表hkey_local_machine節點
    registry.performancedata-------------->指向注冊表hkey_performance_data節點
    registry.users-------------->指向注冊表hkey_users節點
    */
    regsubkey = regrootkey.opensubkey(strregpath);
    string[] strdsnlist = regsubkey.getvaluenames();
    
    ///關閉
    regsubkey.close();
    regrootkey.close();    
這樣就實現了dsn service list的讀取。
最大的網站源碼資源下載站,
新聞熱點
疑難解答