Jump to content


This is a ready-only archive of the InstallSite Forum. You cannot post any new content here. / Dies ist ein Archiv des InstallSite Forums. Hier können keine neuen Beiträge veröffentlicht werden.
Photo

Create a Data Link (.udl) during install


3 replies to this topic

cgilley

cgilley
  • Members
  • 8 posts

Posted 24 July 2001 - 22:45

I have a package that installs an Access db in a subfolder of the installdir.  After this db is installed, I want a CA to create a Microsoft Data Link (udl) file that will point to it.  Just generating a text file with the .udl extension doesn't work, although it looks like it should.  I'd prefer a solution using vbscript, but am open to any ideas.  
TIA

JWolters

JWolters
  • Members
  • 3 posts

Posted 25 July 2001 - 14:42

This is the code we use in our installations:

=====
function WriteUDL(szPath, szFile , szConnect)
NUMBERnvI;
   NUMBERnvFileHandle;  
   STRINGszChar;
   NUMBERnvDummy;  
   CHARchChar;  
   NUMBERnResult, nReturn;
   STRINGsvResult;
begin

//delete file if it already exists
szChar = szPath ^ szFile;
DeleteFile (szChar);

   // create UDL      
   OpenFileMode (FILE_MODE_BINARY);  
   CreateFile (nvFileHandle, szPath, szFile);
   
   // write header
   // #FF #FE    
   Sprintf(szChar, "%c", 0xFF);
   WriteBytes (nvFileHandle, szChar, 0,  1);
   Sprintf (szChar, "%c", 0xFE);
   WriteBytes (nvFileHandle, szChar, 0, 1);

Sprintf (szChar, "%c", 0x00);
   // write connectstring in UNICode
   for nvI = 0 to StrLength(szConnect)
   
   WriteBytes (nvFileHandle, szConnect, nvI, 1);
   WriteBytes (nvFileHandle, szChar, 0, 1);
   
   endfor;

   Sprintf(szChar, "%c", 0x00);
   WriteBytes (nvFileHandle, szChar, 0,  1);
   Sprintf (szChar, "%c", 0x00);
   WriteBytes (nvFileHandle, szChar, 0, 1);
     
   CloseFile (nvFileHandle);

end;
=====

You can call it this way:

WriteUDL (sDIRudl, sFILEudl, "[oledb]\r ; Everything after this line is an OLE DB initstring\r Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + sDIRmdb ^ sFILEmdb + ";Persist Security Info=False");


cgilley

cgilley
  • Members
  • 8 posts

Posted 22 August 2001 - 20:10

(When reading the following, please bear in mind that I am a complete Simpleton when it comes to Installscript)
OK, I'm trying to implement the code JWolters so kindly provided above.  I have a CA which includes that function and an entry point function that calls it, passing the necessary filename and directory parameters.  The problem is, the file is simply not created.  I know the functions are both running, because I added a message box to each one so I could "see" in the install that they were actually running; and they are.  However, after the install is complete, there is no udl file.    I feel like there must be some small but obviously critical thing I am missing, but d&#%^ed if I can figure it out.  I'll paste in the complete script of the CA below.  Any help is greatly appreciated!

////////////////////////////////////////////////////////////////////////////////
//                                                                            
//  IIIIIII SSSSSS                                                            
//    II    SS                          InstallShield ®                    
//    II    SSSSSS      © 1996-2000, InstallShield Software Corporation    
//    II        SS                     All rights reserved.            
//  IIIIIII SSSSSS                  
//                                                                            
//                                                                            
//  This template script provides the code necessary to build an entry-point
//  function to be called in an InstallScript custom action.
//                                                                            
//                                                                            
//    File Name:  Setup.rul                                                  
//                                                                            
//  Description:  InstallShield script                                        
//
////////////////////////////////////////////////////////////////////////////////

// Include Isrt.h for built-in InstallScript function prototypes.
#include "isrt.h"

// Include Iswi.h for Windows Installer API function prototypes and constants,
// and to declare code for the OnBegin and OnEnd events.
#include "iswi.h"

   // The keyword export identifies Call_WriteUDL() as an entry-point function.
   // The argument it accepts must be a handle to the Installer database.
   export prototype Call_WriteUDL(HWND);  
   prototype WriteUDL(STRING, STRING, STRING);
///////////////////////////////////////////////////////////////////////////////
//                                                                          
// Function:  Call_WriteUDL
//                                                                          
//  Purpose:  This function will be called by the script engine when
//            Windows™ Installer executes your custom action (see the "To
//            Do," above).
//                                                                          
///////////////////////////////////////////////////////////////////////////////
function Call_WriteUDL(hMSI)  
   // Declare local variables.
   STRING sDIRudl;
   STRING sFILEudl;
   STRING sDIRmdb;
   STRING sFILEmdb;
   
begin            

   // Script that will be executed when Call_WriteUDL is called.
   sDIRudl = TARGETDIR ^ "\DataParc\database";
   sFILEudl = "ctc_config.udl";
   sDIRmdb = TARGETDIR ^ "\DataParc\database";
   sFILEmdb = "ctc_config.mdb";
   SprintfBox(INFORMATION, "Call_WriteUDL", "The entry point function is running");
   WriteUDL (sDIRudl, sFILEudl, "[oledb]\r ; Everything after this line is an OLE DB initstring\r Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + sDIRmdb ^ sFILEmdb + ";Persist Security Info=False");
end;

//////////////////////////////////////////////////////////////////////////////
//
// Function:  WriteUDL
//
// Purpose:   Creates a Microsoft Windows Data Link File (.udl)
//             using the supplied filename and path info.
//
//////////////////////////////////////////////////////////////////////////////
function WriteUDL(szPath, szFile , szConnect)
NUMBER nvI;
NUMBER nvFileHandle;  
STRING szChar;
NUMBER nvDummy;  
CHAR chChar;  
NUMBER nResult, nReturn;
STRING svResult;
begin

//delete file if it already exists
szChar = szPath ^ szFile;
DeleteFile (szChar);

  // create UDL      
  OpenFileMode (FILE_MODE_BINARY);  
  CreateFile (nvFileHandle, szPath, szFile);

  // write header
  // #FF #FE    
  Sprintf (szChar, "%c", 0xFF);
  WriteBytes (nvFileHandle, szChar, 0,  1);
  Sprintf (szChar, "%c", 0xFE);
  WriteBytes (nvFileHandle, szChar, 0, 1);

  Sprintf (szChar, "%c", 0x00);
  // write connectstring in UNICode                
  for nvI = 0 to StrLength(szConnect)
   
  WriteBytes (nvFileHandle, szConnect, nvI, 1);
  WriteBytes (nvFileHandle, szChar, 0, 1);
   
  endfor;

  Sprintf (szChar, "%c", 0x00);
  WriteBytes (nvFileHandle, szChar, 0,  1);
  Sprintf (szChar, "%c", 0x00);
  WriteBytes (nvFileHandle, szChar, 0, 1);
     
  CloseFile (nvFileHandle);
  SprintfBox(INFORMATION, "WriteUDL", "The WriteUDL function is running");
end;
// To Do:  Handle initialization code when each sequence (User Interface and
//         Execute) starts.
// function OnBegin()
// begin
// end;

// To Do:  Write clean-up code when each sequence (User Interface and Execute)
//         ends.
// function OnEnd()
// begin
// end;


cgilley

cgilley
  • Members
  • 8 posts

Posted 23 August 2001 - 00:45

OK, I've made some progress.  The problem seems to be in the path strings in the calling function.  If I put in hard coded strings, with double backslashes between path elements, it works.  However, specifying a path as TARGETDIR ^ "subfolder\\subfolder" does not work.  So now, my question is - how does one reference the INSTALLDIR in a function?