Search code examples
nsis

Detect if an instance is running with kernel32::CreateMutexA


I'm working on an NSIS installer, and trying to check if a certain application is running before uninstalling. So, I use kernel32::CreateMutexA call. Here is the chunk:

System::Call 'kernel32::CreateMutexA(i 0, i 0, t "cmd.exe") i .r1 ?e'
Pop $R0
StrCmp $R0 0 +3
    MessageBox MB_USERICON "The application is already running."
Abort

I put it into un.onInit. Trouble is, the process (cmd.exe here) is never detected.

Did I miss something?

Tx.


Solution

  • I found a simple solution; using FindProcDLL plugin.

    So:

    FindProcDLL::FindProc "cmd.exe"
    Pop $R0
    StrCmp $R0 0 +3
     MessageBox MB_USERICON "The application is already running." IDOK
    Abort
    

    P.S. FindProcDLL.dll must be copied into /Plugins.