Skip to content

Instantly share code, notes, and snippets.

@igorpopovio
Last active June 2, 2022 14:03
Show Gist options
  • Save igorpopovio/f4b65b2df57f329b8e24 to your computer and use it in GitHub Desktop.
Save igorpopovio/f4b65b2df57f329b8e24 to your computer and use it in GitHub Desktop.
Small example on how to get some information from the registry...
#include "Ifx.h"
#define TITLE "RegDBSetKeyValueEx & RegDBGetKeyValueEx"
export prototype MyFunction(HWND);
function MyFunction(hMSI)
STRING szKey, szNumName, szNumValue, svNumValue, szTitle, szMsg;
NUMBER nType, nSize, nvType, nvSize;
begin
szKey = "SOFTWARE\\Wow6432Node\\Company Ltd.\\COMPANY\\20144";
szNumName = "ExePath";
szNumValue = "12345";
nType = REGDB_STRING;
nSize = -1;
RegDBSetDefaultRoot(HKEY_LOCAL_MACHINE);
if (RegDBGetKeyValueEx (szKey, szNumName, nvType, svNumValue, nvSize) < 0) then
MessageBox ("RegDBGetKeyValueEx failed.", SEVERE);
else
szMsg = "%s has value: %s\n\nThis data is %d bytes.";
SprintfBox (INFORMATION, TITLE, szMsg, szNumName, svNumValue, nvSize);
endif;
// MsiSetProperty(hMSI, "USERNAME", svName);
end;
#define KEY1 "SOFTWARE"
#define KEY2 "SOFTWARE\\Microsoft"
#define KEY3 "SOFTWARE\\Wow6432Node\\Company Ltd.\\COMPANY"
#define TITLE "RegDBQueryKey Example"
export prototype QueryingForRegistryKeys(HWND);
function QueryingForRegistryKeys(hMSI)
STRING szMsg, nvItem;
NUMBER nReturn, nItem, nCount;
LIST listSubKeys, listNames;
begin
listSubKeys = ListCreate(STRINGLIST);
listNames = ListCreate(STRINGLIST);
if ((listNames = LIST_NULL) || (listSubKeys = LIST_NULL)) then
MessageBox ("Unable to create necessary lists.", SEVERE);
abort;
endif;
RegDBSetDefaultRoot(HKEY_LOCAL_MACHINE);
nReturn = RegDBQueryKey(KEY3, REGDB_KEYS, listSubKeys);
if (nReturn < 0) then
MessageBox("First call to RegDBQueryKey failed.", SEVERE);
else
szMsg = "Subkeys under " + KEY3 + " key:";
SdShowInfoList(TITLE, szMsg, listSubKeys);
endif;
nReturn = RegDBQueryKey(KEY2, REGDB_NAMES, listNames);
if (nReturn < 0) then
MessageBox("Second call to RegDBQueryKey failed.", SEVERE);
else
szMsg = "Named values under " + KEY2 + " key";
SdShowInfoList(TITLE, szMsg, listNames);
endif;
nReturn = ListGetFirstString(listSubKeys, nvItem);
while (nReturn != END_OF_LIST)
SprintfBox (INFORMATION, TITLE, "%s", nvItem);
nReturn = ListGetNextString (listSubKeys, nvItem);
endwhile;
ListDestroy (listNames);
ListDestroy (listSubKeys);
// how to disable a feature in Basic MSI projects - from InstallScript
MsiSetFeatureState(hMSI, "GitIgnore", INSTALLSTATE_ABSENT);
// must be called from:
// Custom Actions -> Sequence -> Install UI Sequence -> After MigrateFeatureStates
MsiSetTargetPath(hMSI, "MYDIRECTORY", customInstallationPath);
// this works only if you add a new directory from: "Application Data" -> "Files and Folders"
// don't forget to set the DIRECTORY IDENTIFIER to "MYDIRECTORY" (see the function call above)
// right click on directory name and select properties to get to the DIRECTORY IDENTIFIER
end;
@jorgerodriguezg1988
Copy link

Hi Igor! Excuse me please, I am junior at InstallScript and I am trying to read a XML file from InstallScript but I can't. Suddenly, Do you know how to do this? Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment