Skip to content
⌘ NSIS Forum Archive

Exit all instances of the application before install via event signal

3 posts

CryoMade#

Exit all instances of the application before install via event signal

Hopefully this would be useful for everyone, who will want to auto exit application even it was started under the different user, in other session (via Fast User Switch feature).

My situation is that app runs under user rights, but installer runs with admin rights. And I need to shutdown all the instances of the app before install.

Maybe it makes sense to add this or similar code to help as it quite common task?

Following code will create or open existing event and make it signaled.


Function .onInit
StrCpy $7 'Global\ExitNowEvent'
System::Call 'kernel32::CreateEvent(p0, i0, i0, tr7) p.r8'
System::Call 'kernel32::SetEvent(pr8)'
FunctionEnd
Following C++ code will create event with full access rights for everyone to the event.


SECURITY_ATTRIBUTES sa = { 0 };
sa.nLength = sizeof(sa);
sa.bInheritHandle = false;
PSECURITY_DESCRIPTOR pSD = 0;
pSD = (PSECURITY_DESCRIPTOR) LocalAlloc(LPTR, SECURITY_DESCRIPTOR_MIN_LENGTH);
if (pSD && InitializeSecurityDescriptor(pSD, SECURITY_DESCRIPTOR_REVISION))
{
SetSecurityDescriptorDacl(pSD, true, NULL, false);// Passing NULL as DACL to allow full access by everyone
sa.lpSecurityDescriptor = pSD;
}

hExitImmediatelyEvent = CreateEvent(sa.lpSecurityDescriptor ? &sa : NULL,
false, false, L"Global\\ExitNowEvent");