# _ODBC.PL # ---------- # This is managment system script designed to check for and # install the MS SQL Server ODBC driver. It also checks # for a particular ODBC DSN. If it does not exist it will # be created. # THIS SCRIPT assumes that ODBC has been already installed # on the machine. # # Dave Roth # Roth Consulting # http://www.roth.net # use Win32::Registry; use Win32::ODBC; $Dsn = "ConfigServer"; $ODBCDriver = "SQL Server"; $DestDir = "$ENV{WINDIR}\\System32"; $REMOTE_DRIVER_DIR = '\\\\server\perlshare$\ODBC\SQLServerDriver'; %DriverList = Win32::ODBC::Drivers(); if( ! defined $DriverList{$ODBCDriver} ) { my $Key; # Copy all the SQL Server ODBC Driver files... `xcopy "$REMOTE_DRIVER_DIR\*.*" "$DestDir\*.*" /s`; # We need to install the SQL Server driver. if( $HKEY_LOCAL_MACHINE->Create( "SOFTWARE\\ODBC\\ODBCINST.INI\\$ODBCDriver", $Key ) ) { my $SubKey; $Key->SetValueEx( 'APILevel', 0, REG_SZ, "2" ); $Key->SetValueEx( 'ConnectFunctions', 0, REG_SZ, "YYY" ); $Key->SetValueEx( 'CPTimeout', 0, REG_SZ, "60" ); $Key->SetValueEx( 'Driver', 0, REG_SZ, "$DestDir\\SQLSRV32.DLL" ); $Key->SetValueEx( 'DriverODBCVer', 0, REG_SZ, "03.50" ); $Key->SetValueEx( 'FileUsage', 0, REG_SZ, "0" ); $Key->SetValueEx( 'Setup', 0, REG_SZ, "$DestDir\\SQLSRV32.DLL" ); $Key->SetValueEx( 'SQLLevel', 0, REG_SZ, "1" ); if( $Key->Create( 'FileList', $SubKey ) ) { $SubKey->SetValueEx( 'CTL3D32.DLL', 0, REG_SZ, "$DestDir\\CTL3D32.DLL" ); $SubKey->SetValueEx( 'DBNMPNTW.DLL', 0, REG_SZ, "$DestDir\\DBNMPNTW.DLL" ); $SubKey->SetValueEx( 'DRVSSRVR.HLP', 0, REG_SZ, "$DestDir\\DRVSSRVR.HLP" ); $SubKey->SetValueEx( 'MSVCRT40.DLL', 0, REG_SZ, "$DestDir\\MSVCRT40.DLL" ); $SubKey->SetValueEx( 'SQLSRV32.DLL', 0, REG_SZ, "$DestDir\\SQLSRV32.DLL" ); $SubKey->Close(); } $Key->Close(); # Update the installed driver list... if( $HKEY_LOCAL_MACHINE->Create( 'SOFTWARE\ODBC\ODBCINST.INI\ODBC Drivers', $Key ) ) { $Key->SetValueEx( $ODBCDriver, 0, REG_SZ, "Installed" ); $Key->Close(); } } } %DSNList = Win32::ODBC::DataSources(); # We should probably perform a better test to take into account # mixed case... if( ! defined $DSNList{$Dsn} ) { if( ! Win32::ODBC::ConfigDSN( ODBC_ADD_DSN, $ODBCDriver, ("DSN=$Dsn", "Description=The Configuration Database", "Server=dbserver", "Trusted_Connection=Yes", "Database=ConfigLogs" ) ) ) { print "Unable to create DSN: " . Win32::ODBC::Error() . "\n"; } } print "Finished.\n";