![]() |
Set an event during uninstall
I'm trying to use System::call to set an event while uinstalling which will cause my application to quit.
I've seen references to ways of checking if a process is running, however for many users being told that something is running doesn't help them figure out how to remove the program. And killing the process seems fairly evil too. So I'd rather build a mechanism into my app to nicely exit. Here's a code snippet: System::Call "kernel32::OpenEventA(i 1048578, i 0, t 'myAppShutdownEvent') i .r0" IntCmp $0 0 eventNotFound System::Call "kernel32::SetEventA( i r0 ) i .r1" goto processNotRunning eventNotFound: ... processNotRunning: ... It seems like this should work, but I get a questionable value back in $0 from OpenEvent (usually a number between 100-200). Clearly that's not null, but its a pretty low number for a handle too. (My C++ test program that sets this event typically gets a handle value in the 4000 range (i.e. $ff4 most of the time today...). And SetEvent is definitely not setting the event with that return as the handle. I'm sure its something obvious I'm missing, but I can't figure it out, and haven't been able to find anything similar enough already asked or in the FAQs to get past this. Thanks! ...Jason |
It might be an idea to replace 1048578 with the actual constants that you used with mod signs in between. I'm sure you've got the value right, but it's worth a try.
-Stu |
By inspection, your permissions value looks OK, being a combination of SYNCHRONIZE (0x00100000L) and EVENT_MODIFY_STATE (0x0002). I suggest that you make these two values into NSIS !defines and use these in your code as this will greatly improve its readability.
If OpenEvent fails it sets the system error value, which you can retrieve from the System plugin by using the '?e' option as part of the return value section of the call (if my memory serves - it is mentioned in the doco for the System plugin). This will give you some clues as to what is amiss. Common reasons for the OpenEvent failing (apart from the obvious such as Event does not exist) include inheritance issues i.e. trying to open an event that the parent process does not mark for its children to inherit, not opening the Event with sufficient permissions, and an invalid permissions value. You really need that information from GetLastError to determine what exactly is going on. BTW: What you are doing is defnitely possible - I have done it from completely within NSIS, using an Event to pass control from one instance of a NSIS program to another instance of the same program; all done with System plugin calls. Duncan |
Duncan,
It appears GetLastError is returning 126 (ERROR_MOD_NOT_FOUND). Since kernel32.dll clearly isn't missing, I'm not sure this helps any... |
The System plug-in itself usually raises ERROR_MOD_NOT_FOUND with some LoadLibrary calls. This is why you should use the "?e" modifier, instead of calling GetLastError with System.dll itself. Have you used the modifier or GetLastError directly?
|
| All times are GMT. The time now is 05:58. |
Copyright © 1999 - 2010 Nullsoft. All Rights Reserved.