简体   繁体   English

进入服务卸载程序(C#)

[英]Getting into service uninstaller (c#)

Right, 对,

So I have a Windows service written in C#. 所以我有一个用C#编写的Windows服务。 I've already found the 'ProjectInstaller.cs' where I do some stuff, like set dependencies and service name during install. 我已经找到了“ ProjectInstaller.cs”,可以在其中进行一些操作,例如在安装过程中设置依赖项和服务名称。

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" 虽然我知道到处都是很少的解决方法,例如只是从注册表中删除注册表项,但我想考虑一个用户(具有本地管理员权限)使用scinstallutil.exe卸载服务-本质上,我只是想该服务将声明写到数据库中,说“嘿,我正在被bobsmith卸载”

Possible? 可能? Doable? 可行吗

Update - This is what I have in my ProjectInstaller.cs - not working... 更新-这是我在ProjectInstaller.cs中拥有的内容-无法正常工作...

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事件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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