program CreateODBCSource;

{$APPTYPE CONSOLE}

uses
  SysUtils,
  ComObj,
  ActiveX,
  Variants;

{
   Esta rotina usa automação OLE interagindo com o WSH (Windows Scripting Host)
   para criar uma fonte de dados ODBC.

   Parâmetros:
      DataSourceName - nome da fonte de dados a ser registrada
      DLLDriver - caminho da DLL do cliente do SGBD
      DBServer - nome ou endereço IP do servidor do banco de dados
      DBName - nome do banco de dados no servidor DBServer
      DBType - tipo da conexão registrado no ODBC
}
procedure CreateODBCDataSource(
  const DataSourceName, DLLDriver, DBServer, DBName, DBUser, DBType: string);
const
  cRegKey1 = 'HKLM\Software\ODBC\ODBC.INI\';
  cRegKey2 = 'HKLM\Software\ODBC\ODBC.INI\ODBC Data Sources\';
var
  oWshShell: OleVariant;
begin
  oWshShell := CreateOleObject('WScript.Shell');
  try
    oWshShell.RegWrite(cRegKey1 + DataSourceName + '\Driver', DLLDriver);
    oWshShell.RegWrite(cRegKey1 + DataSourceName + '\Server', DBServer);
    oWshShell.RegWrite(cRegKey1 + DataSourceName + '\Database', DBName);
    oWshShell.RegWrite(cRegKey1 + DataSourceName + '\LastUser', DBUser);
    oWshShell.RegWrite(cRegKey2 + DataSourceName, DBType);
  finally
    oWshShell := Null;
  end;
end;

begin
  CoInitialize(nil);
  try
    CreateODBCDataSource(
      'CRM_DB',                               // Nome da fonte de dados ODBC
      'C:\\WINNT\\System32\\sqlsrv32.dll',    // DLL cliente do SGBD
      'SRVDADOS',                             // Nome/end. IP do servidor
      'CRM_PRODUCAO',                         // Nome do BD no servidor
      'sa',                                   // Usuário do BD
      'SQL Server');                          // Tipo do SGBD
  finally
    CoUninitialize;
  end;
end.


_________________________________________________________________
Instale a Barra de Ferramentas com Desktop Search e ganhe EMOTICONS para o 
Messenger! É GRÁTIS!
http://www.msn.com.br/emoticonpack

Responder a