procedure IncrementSharedCount(const Is64Bit: Boolean; const Filename: String; const AlreadyExisted: Boolean);
Increments or initializes the reference count for the specified file in the following registry key:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\SharedDLLs
64-bit versions of Windows have two separate SharedDLLs keys, one for 64-bit files and one for 32-bit files. If Is64Bit is True, the 64-bit SharedDLLs key will be updated, otherwise the 32-bit SharedDLLs key will be updated. The setting of this parameter should correspond to the bitness of the file; for example, if it is a 32-bit DLL located in the 32-bit System directory, you should specify False. You may also specify Is64BitInstallMode in which case it will use the current install mode to determine which key to open.
Pass True in the AlreadyExisted parameter if the file already exists; in this case the initial reference count for the file will be 2 if the value for the file doesn't already exist in the registry. (This behavior is in line with Microsoft's requirements.)
An exception will be raised if the registry key cannot be opened for write access.
Filename must be reachable in the current process. This means, for example, that a 32-bit installer passing True in the Is64Bit parameter must pass a Sysnative path if the file is located under {sys}. Use ApplyPathRedirRules as shown in the example below to make that adjustment automatically. (Calling ApplyPathRedirRules for files outside of {sys} isn't necessary, but it doesn't hurt.)
var
File64Bit, AlreadyExisted: Boolean;
begin
// Increment count of TestIncSharedCount.dll located in the System directory.
// Setting File64Bit to...
// - False will update the 32-bit SharedDLLs key
// - True will update the 64-bit SharedDLLs key
// - Is64BitInstallMode will use Setup's install mode to determine which key to update
File64Bit := Is64BitInstallMode;
// AlreadyExisted should be True if the file existed before installation
AlreadyExisted := False;
IncrementSharedCount(File64Bit,
ApplyPathRedirRules(File64Bit, ExpandConstant('{sys}\TestIncSharedCount.dll'), tpCurrent),
AlreadyExisted);
end;