簡體   English   中英

如何收到有關我的服務已被卸載的通知?

[英]How can I receive notification that my service is being uninstalled?

我想知道是否可以收到有關我的服務正在卸載的通知?

我可以收到有關我的服務已停止的通知。

    protected override void OnStop()
    {
        base.OnStop();
    }

但是如何知道它是否已卸載?

事實證明,可以使用Service Control(sc)命令從安裝程序中調用自定義參數:

 sc control <name_of_service> 129

其中129是由您的服務處理的自定義代碼:

    protected enum customCommands
    {
        install = 128,
        uninstall = 129,
    }

    protected override void OnCustomCommand(int command)
    {
        base.OnCustomCommand(command);

        if (command >= 128 && command <= 255)
        {
            customCommands cust = (customCommands)command;

            switch (cust)
            {
                case customCommands.install:
                    break;

                case customCommands.uninstall:
                    break;

                default:
                    break;
            }
        }
    }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM