Advertisement
TLama

Untitled

Feb 20th, 2015
684
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 1.03 KB | None | 0 0
  1. [Setup]
  2. AppId=2336BF63-DF20-445F-AAE6-70FD7E2CE1CF
  3. AppName=My Program
  4. AppVersion=1.5
  5. DefaultDirName={pf}\My Program
  6.  
  7. [Code]
  8. #ifdef UNICODE
  9.   #define AW "W"
  10. #else
  11.   #define AW "A"
  12. #endif
  13.  
  14. const
  15.   ERROR_ALREADY_EXISTS = 183;
  16.  
  17. function CreateMutex(lpMutexAttributes: LongWord; bInitialOwner: BOOL; lpName: string): THandle;
  18.   external 'CreateMutex{#AW}@kernel32.dll stdcall';
  19.  
  20. function InitializeSetup: Boolean;
  21. begin
  22.   Result := True;
  23.   // it's quite handy to use the AppId directive to be the mutex name because it should be unique;
  24.   // if the CreateMutex function call fails, let the setup start no matter what happened; if this
  25.   // call succeeded, and the mutex already exists, there is another process that created it - let
  26.   // the setup exit telling this to the user
  27.   if (CreateMutex(0, False, '{#SetupSetting('AppId')}') <> 0) and (DLLGetLastError = ERROR_ALREADY_EXISTS) then
  28.   begin
  29.     Result := False;
  30.     MsgBox('Another instance of the setup with this AppId is running.', mbInformation, MB_OK);
  31.   end;
  32. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement