安装后无法使用Service Installer中的ServiceName来启动

我正在尝试安装Windows服务,因此我从设计器中添加了安装程序(右键单击广告安装程序),然后添加了AfterInstall方法,但无法从那里引用我的服务:

[RunInstaller(true)]
public partial class ProjectInstaller : System.Configuration.Install.Installer
{
    public ProjectInstaller()
    {
        InitializeComponent();
        AfterInstall += new InstallEventHandler(ServiceInstaller_AfterInstall);
    }
    void ServiceInstaller_AfterInstall(object sender,InstallEventArgs e)
    {
        ProjectInstaller serviceInstaller = (ProjectInstaller)sender;

        using (ServiceController sc = new ServiceController(serviceInstaller.ServiceName)) //<- ServiceName does not exist
        {
            sc.Start();
        }
    }
}

我在其他帖子上看到生成的代码通常是ServiceInstaller(我有一个ProjectInstaller),更改类名不能解决问题,实际上它告诉我InitializeComponent()没有定义。

mingkaifeng22 回答:安装后无法使用Service Installer中的ServiceName来启动

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3117962.html

大家都在问