Go Back   Winamp & Shoutcast Forums > Developer Center > NSIS Discussion

Reply
Thread Tools Search this Thread Display Modes
Old 25th June 2019, 11:23   #1
CryoMade
Junior Member
 
Join Date: Jun 2019
Posts: 2
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.

code:

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.

code:

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");


CryoMade is offline   Reply With Quote
Old 25th June 2019, 18:15   #2
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,097
ExitNowEvent is not a good name, use MyAppnameExitNowEvent or a guid.

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 26th June 2019, 10:32   #3
CryoMade
Junior Member
 
Join Date: Jun 2019
Posts: 2
Yes, I use app specific guid there, changed name just for the publication.
CryoMade is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Developer Center > NSIS Discussion

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump