Instead of intercepting registry access for the dll, you can use the inter-process locking mechanism to write values ββto the registry for your own application. The idea is that the lock obtained by the instance1 instance is not released until its "instance" DLL reads the value, so that when instance2 is started, it will not get the lock until instance1 is complete. You will need a locking mechanism that works between processes to do this. For example, mutexes.
To create mutexes:
procedure CreateMutexes(const MutexName: string); //Creates the two mutexes checked for by the installer/uninstaller to see if //the program is still running. //One of the mutexes is created in the global name space (which makes it //possible to access the mutex across user sessions in Windows XP); the other //is created in the session name space (because versions of Windows NT prior //to 4.0 TSE don't have a global name space and don't support the 'Global\' //prefix). const SECURITY_DESCRIPTOR_REVISION = 1; // Win32 constant not defined in Delphi 3 var SecurityDesc: TSecurityDescriptor; SecurityAttr: TSecurityAttributes; begin // By default on Windows NT, created mutexes are accessible only by the user // running the process. We need our mutexes to be accessible to all users, so // that the mutex detection can work across user sessions in Windows XP. To // do this we use a security descriptor with a null DACL. InitializeSecurityDescriptor(@SecurityDesc, SECURITY_DESCRIPTOR_REVISION); SetSecurityDescriptorDacl(@SecurityDesc, True, nil, False); SecurityAttr.nLength := SizeOf(SecurityAttr); SecurityAttr.lpSecurityDescriptor := @SecurityDesc; SecurityAttr.bInheritHandle := False; CreateMutex(@SecurityAttr, False, PChar(MutexName)); CreateMutex(@SecurityAttr, False, PChar('Global\' + MutexName)); end;
To free a mutex, you must use the ReleaseMutex API and purchase the created mutex, you must use the OpenMutex API.
For CreateMutex see: http://msdn.microsoft.com/en-us/library/ms682411(VS.85).aspx
For OpenMutex see: http://msdn.microsoft.com/en-us/library/ms684315(v=VS.85).aspx
For ReleaseMutex see: http://msdn.microsoft.com/en-us/library/ms685066(v=VS.85).aspx
source share