A windows service creates a registry value (for an Excel add-in) under HKEY_CURRENT_USER
registry key for each logged on user (by calling ImpersonateLoggedOnUser()
and RegSetValueEx()
).
I need to delete this registry value when a user logs off, including system shutdown.
If it is not deleted at log off, and the software is uninstalled by one user then the entry in the registry remains for any other user that logged on during the lifetime of the service which causes a message box error to be displayed each time Excel begins because it is attempting to load an add-in that no longer exists.
Considered but rejected the following:
SetConsoleCtrlHandler()
because there is no indication of what user is logging off.REG_OPTION_VOLATILE
because it is effective only when creating keys and I am only creating a value (did not thoroughly investigate so may not have been solution even if I was creating a key).
Are there any other mechanisms that would provide a solution to this? Windows versions are XP, Vista and 7.