简体   繁体   中英

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 local 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...
    }

在设计器中添加一个ServiceInstaller对象(如果尚不存在),并订阅BeforeUninstall事件

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM