用 C# & Java 在目标机器上部署 ODBC

| 2 Comments

所有 ODBC 数据源名都存放在 Windows 注册表下的:HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI\ODBC Data Sources(系统 DSN)和 HKEY_CURRENT_USER\Software\ODBC\ODBC.INI\ODBC Data Sources(用户DSN)键值中。

2 Comments

C# 例子:

private void button1_Click(object sender, System.EventArgs e)
  {
   RegistryKey hklm = Registry.LocalMachine;
   RegistryKey hkodbc= hklm.OpenSubKey ("SOFTWARE\\ODBC\\ODBC.INI",true);
   RegistryKey odbcDataSource=hkodbc.OpenSubKey("ODBC Data Sources",true);
   odbcDataSource.SetValue("SCCHZ-APS-BOD65","SQL Server");//在ODBC Data Sources加一条记录

   RegistryKey newodbc = hkodbc.CreateSubKey("SCCHZ-APS-BOD65");
   newodbc.SetValue("Database","BOD");
   newodbc.SetValue("Description","SCCHZ-APS-BOD65");
   newodbc.SetValue("Driver","C:\WINNT\System32\SQLSRV32.dll");
   newodbc.SetValue("LastUser","apsbo");
   newodbc.SetValue("Server","svr05405");
   MessageBox.Show("生成完毕");
  }

C# 例子:

private void button1_Click(object sender, System.EventArgs e)
  {
   RegistryKey hklm = Registry.LocalMachine;
   RegistryKey hkodbc= hklm.OpenSubKey ("SOFTWARE\\ODBC\\ODBC.INI",true);
   RegistryKey odbcDataSource=hkodbc.OpenSubKey("ODBC Data Sources",true);
   odbcDataSource.SetValue("SCCHZ-APS-BOD65","SQL Server");//在ODBC Data Sources加一条记录

   RegistryKey newodbc = hkodbc.CreateSubKey("SCCHZ-APS-BOD65");
   newodbc.SetValue("Database","BOD");
   newodbc.SetValue("Description","SCCHZ-APS-BOD65");
   newodbc.SetValue("Driver","C:\WINNT\System32\SQLSRV32.dll");
   newodbc.SetValue("LastUser","apsbo");
   newodbc.SetValue("Server","svr05405");
   MessageBox.Show("生成完毕");
  }

Java:

1.通过 JNI 的方法调用 DLL,在 DLL 里面再进行注册表的读写工作
2.j2se 1.4中的 java.util.prefs.Preferences
3.通过 mircosof t的 SDK FOR JAVA 内的包,下载
通过RegKey类,来访问CLASSES_ROOT\Word.Basic\CLSID
的键值

import wb70en32.*;
import com.ms.com.*;
import com.ms.lang.*;

// Get the Registry Key for CLASSES_ROOT
            RegKey root = RegKey.getRootKey(RegKey.CLASSES_ROOT);

// From CLASSES_ROOT, get the key for Word.Basic
            RegKey wbkey = new RegKey(root,
                "Word.Basic", RegKey.KEYOPEN_READ);

// From Word.Basic, get the CLSID
            RegKey clsid = new RegKey(wbkey, "CLSID",
                RegKey.KEYOPEN_READ);

// Retrieve the CLSID from the CLSID key (it's the default value)
            String classID = ((RegKeyEnumValueString)clsid.
                enumValue(0)).value;

About this Entry

This page contains a single entry by Sky published on September 22, 2005 10:29 AM.

一个完整的网上追捕的原程序 was the previous entry in this blog.

通过 JNI 远程注册表访问 is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.