Getting into service uninstaller (c#)
Right,
So I have a Windows service written in C#. I've already found the 'ProjectInstaller.cs' where I do some stuff, like set dependencies and service name during install.
What I'm not finding is how to hook into the uninstall process of the server.
While I know there's little workarounds here and there, such as just trashing the key from the registry, I'd like to account for a user (with l开发者_Python百科ocal admin rights) uninstalling the service with sc
or installutil.exe
- essentially, I simply want the service to write a statement to a database saying "Hey, I'm being uninstalled by bobsmith"
Possible? Doable?
Update - This is what I have in my ProjectInstaller.cs - not working...
namespace blahblah
{
[RunInstaller(true)]
public partial class ProjectInstaller : Installer
{
public ProjectInstaller()
{
InitializeComponent();
BeforeUninstall += new InstallEventHandler(ProjectInstaller_BeforeUninstall);
}
private void ProjectInstaller_BeforeUninstall(object sender, InstallEventArgs e)
{
/// do stuff...
}
Add a ServiceInstaller object in your designer (if one is not already there) and subscribe to the BeforeUninstall event
精彩评论