Thursday, November 20, 2014

Check PostgreSQL version on the machine

Hi All,
Please use the reference from the below custom action I have created for checking the PostgreSQL version on your machine.

function CheckPostgresSQLVersion(hMSI)
STRING ProcessName, szLine, Text,svReturnLine;
NUMBER nvFileHandle, ExitCode,nvResult,nvLineNumber,nLoc;
begin
ProcessName = "CheckPostgresSQLVersion";
OpenFileMode (FILE_MODE_APPEND);
if (CreateFile (nvFileHandle, SUPPORTDIR, "PostgresSQLVersion.bat") = 0) then
szLine = "psql --version";
WriteLine(nvFileHandle, szLine);
endif;

// Close the file.
CloseFile (nvFileHandle);

ExitCode = RunApplication(hMSI, SUPPORTDIR^"PostgresSQLVersion.bat", " >PostgresSQLVersion.txt", "");
if (ExitCode = 0) then
GetFullErrorText(hMSI, 60, SUPPORTDIR, "PostgresSQLVersion.txt", Text);
nvResult = FileGrep (SUPPORTDIR ^ "PostgresSQLVersion.txt", "psql (PostgreSQL)", svReturnLine,nvLineNumber, RESTART);
if(nvResult = 0) then
nLoc = StrFind(svReturnLine,"9.1");

if(nLoc<0 p="" then=""> MsiSetProperty(hMSI, "INVALID_POSTGRESQL_VERSION", "1");
MessageBox("Invalid version of PostgreSQL",SEVERE);
else
MsiSetProperty(hMSI, "INVALID_POSTGRESQL_VERSION", "0");
endif;
endif;
endif;
DeleteFile(SUPPORTDIR^"PostgresSQLVersion.bat");
end;

Tuesday, April 15, 2014

Aborting from a basic msi project using custom Action

To abort in a basic msi project through a custom action, one needs to return ERROR_INSTALL_FAILURE in the installer code.

The custom actions which gets executed successfully should return the value ERROR_SUCCESS.

Tuesday, March 25, 2014

Remove temporary records in msi database (vbscript)

Set viewlist = Database.OpenView("SELECT * FROM `ComboBox` WHERE `Property`='DEFAULT_ENGINE'")
viewlist.Execute

Set reclist = viewlist.Fetch

' delete any existing LISTBOXPROP records
While Not (reclist Is Nothing)
    viewlist.Modify 6, reclist ' 6 = delete
    Set reclist = viewlist.Fetch
Wend

viewlist.Close

Populating combobox at runtime in basic msi project

////////////////////////////////////////////////////////////////
//
// Function: PopulateDefaultEngineslist
//
//  Purpose:  Populates engines list combobox for selection to be default.
//
//
////////////////////////////////////////////////////////////////
prototype PopulateDefaultEngineslist(HWND,STRING,STRING,STRING);
function PopulateDefaultEngineslist(hMSI,SelectCM,SelectCPE,SelectUE)
HWND hDB, hView,hPropView,hPropRecord, hRecord;
LIST listID;
NUMBER nResult, nCounter;
STRING svListString, szTmp,szFirstItem;
begin
hDB = MsiGetActiveDatabase(hMSI);
MsiDatabaseOpenView(hDB,"SELECT * FROM ComboBox", hView);
    // Create an empty string list.

    listID = ListCreate (STRINGLIST);
    // If an error occurred, report it; then terminate.
    if (listID = LIST_NULL) then
        MessageBox ("Unable to create list.", SEVERE);
        abort;
    endif;

if (ListAddString (listID, "Select Engine", AFTER) < 0) then
MessageBox ("ListAddString failed.", INFORMATION);
endif;

    // Add a string to the list. This string becomes the current element.
if ( SelectCM = "true" ) then
if (ListAddString (listID, "CM", AFTER) < 0) then
MessageBox ("ListAddString failed.", INFORMATION);
endif;

if(szFirstItem == "") then
szFirstItem = "CM";
endif;
endif;

if ( SelectCPE = "true" ) then
if (ListAddString (listID, "CPE", AFTER) < 0) then
MessageBox ("ListAddString failed.", INFORMATION);
endif;

if(szFirstItem == "") then
szFirstItem = "CPE";
endif;
endif;

    // Add a third string; insert it before the current element.
if ( SelectUE = "true" ) then
if (ListAddString (listID, "UE", AFTER) < 0) then
MessageBox ("ListAddString failed.", INFORMATION);
endif;

if(szFirstItem == "") then
szFirstItem = "UE";
endif;
endif;

    // Retrieve and display the current element.

    //ListCurrentString (listID, svString);

nResult = ListGetFirstString (listID, svListString);

while (nResult != END_OF_LIST)
hRecord = MsiCreateRecord(4);
NumToStr(szTmp,nCounter);
MsiRecordSetString(hRecord, 1, "DEFAULT_ENGINE");// Column 1 PROPERTY
MsiRecordSetInteger(hRecord, 2, nCounter); // Column2: Display order of the item
MsiRecordSetString(hRecord, 3, svListString); // Column3: Value to set property to
MsiRecordSetString(hRecord, 4, svListString); // Column4: Display text for item
MsiViewModify(hView, MSIMODIFY_INSERT_TEMPORARY, hRecord);
nCounter=nCounter+1;
nResult = ListGetNextString (listID, svListString);
endwhile;
MsiCloseHandle(hRecord);

MsiViewClose(hView);
MsiCloseHandle(hView);
MsiCloseHandle(hDB);

    // Remove the list from memory.

    ListDestroy (listID);


end;


-----------------------