Hello Friends, today I want to share a script which will help you in preventing multiple instances of an installer simultaneously. For this you need to declare below two prototypes in your setup.rul file.
prototype Kernel32.CreateMutex(byval NUMBER, BOOL, STRING);
prototype Kernel32.ReleaseMutex(HWND);
Below I had used a function named 'CheckMultipleInstance' which will help in preventing multiple instances of an installshield installer to run at a time.
//***************************************************************************
//FUNCTION NAME : CheckMultipleInstance
//Purpose : To prevent multiple instances of setup to run at one time.
//***************************************************************************
function CheckMultipleInstance(hMSI)
STRING strMutex;
HWND hMutex;
NUMBER nError;
begin
strMutex = "MY_SETUPMUTEX" ;
hMutex = Kernel32.CreateMutex(NULL, TRUE, strMutex);
nError = Err.LastDllError();
if (hMutex != 0 && nError == 183) then
MessageBoxEx("Another instance of this setup is already
running","",SEVERE);
ReleaseMutex(hMutex);
if(MsiSetProperty(ISMSI_HANDLE,"ANOTHERINSTANCE","1") ==
ERROR_SUCCESS) then
SprintfMsiLog("CUSTOM LOG: %s","Version is not Valid.");
endif;
abort;
else
if(MsiSetProperty(ISMSI_HANDLE,"ANOTHERINSTANCE","0") ==
ERROR_SUCCESS) then
SprintfMsiLog("CUSTOM LOG: %s","Version is not Valid.");
endif;
endif;
end;
prototype Kernel32.CreateMutex(byval NUMBER, BOOL, STRING);
prototype Kernel32.ReleaseMutex(HWND);
Below I had used a function named 'CheckMultipleInstance' which will help in preventing multiple instances of an installshield installer to run at a time.
//***************************************************************************
//FUNCTION NAME : CheckMultipleInstance
//Purpose : To prevent multiple instances of setup to run at one time.
//***************************************************************************
function CheckMultipleInstance(hMSI)
STRING strMutex;
HWND hMutex;
NUMBER nError;
begin
strMutex = "MY_SETUPMUTEX" ;
hMutex = Kernel32.CreateMutex(NULL, TRUE, strMutex);
nError = Err.LastDllError();
if (hMutex != 0 && nError == 183) then
MessageBoxEx("Another instance of this setup is already
running","",SEVERE);
ReleaseMutex(hMutex);
if(MsiSetProperty(ISMSI_HANDLE,"ANOTHERINSTANCE","1") ==
ERROR_SUCCESS) then
SprintfMsiLog("CUSTOM LOG: %s","Version is not Valid.");
endif;
abort;
else
if(MsiSetProperty(ISMSI_HANDLE,"ANOTHERINSTANCE","0") ==
ERROR_SUCCESS) then
SprintfMsiLog("CUSTOM LOG: %s","Version is not Valid.");
endif;
endif;
end;
This comment has been removed by the author.
ReplyDeleteHi Amit,
ReplyDeleteIt's a very good solution to restrict multiple instances. But where we can call this function in our execution sequence ? Because we have to call this function before extraction of MSI from EXE. So where do we need to call this function ?
Thanks for the blog article.Thanks Again. Keep writing.
ReplyDeletego langaunage online training
azure online training
java online training
salesforce online training
hadoop online training
mulesoft online training
linux online training
etl testing online training
web methods online training