2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

JScriptでODBCのドライバ一覧を表示

Posted at
listODBC.bat
cscript.exe //Nologo listODBC.js
listODBC.js
WScript.Echo("BEGIN");
try {
    // 「SWbemLocator」オブジェクト取得
    var locator = new ActiveXObject("WbemScripting.SWbemLocator");

    // 「SWbemServices」オブジェクト取得(ローカルコンピュータ、名前空間が「root\default」)
    var server = locator.ConnectServer(null, "root\\default");

    // 「SWbemObject」オブジェクト取得(「StdRegProv」オブジェクト)
    var object = server.Get("StdRegProv");

    // 「EnumValues」メソッド取得
    var method = object.Methods_.Item("EnumValues");

    // パラメータ用「SWbemObject」オブジェクト生成
    var params = method.InParameters.SpawnInstance_();

    // パラメータ設定
    params.hDefKey = 0x80000002; // HKEY_LOCAL_MACHINE(0x80000002)
    params.sSubKeyName = "SOFTWARE\\ODBC\\ODBCINST.INI\\ODBC Drivers";

    // メソッド実行(結果パラメータ取得)
    var result = object.ExecMethod_(method.Name, params);

    // 結果を出力
    var names = result.sNames.toArray();
    for (var i = 0; i < names.length; i++) {
        WScript.Echo("" + names[i]);
    }
} catch (e) {
    WScript.Echo("Exception(" + (e.number & 0xFFFF) + "):" + e.message);
}
WScript.Echo("END");

WScript.Quit(0);
2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?