不能使用WiX启动Windows服务?

时间:2022-02-09 20:53:18

I have the following WiX project to install my service:

我有以下WiX项目来安装我的服务:

<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
  <Product Id="GUID" Name="SetupWinService" Language="1049"
           Version="1.0.0.0" Manufacturer="SetupWinService"
           UpgradeCode="GUID">
    <Package InstallerVersion="200" Compressed="yes"
             Languages="1049" SummaryCodepage="1251"
             InstallPrivileges="elevated"/>

    <Media Id="1" Cabinet="media1.cab" EmbedCab="yes" />

    <Directory Id="TARGETDIR" Name="SourceDir">
      <Directory Id="ProgramFilesFolder">
        <Directory Id="WinService" Name="My Windows Service">
        </Directory>
      </Directory>
    </Directory>

    <DirectoryRef Id="WinService">
      <Component Id="WinServiceInstallation" Guid="GUID">
        <File Id="ClientService.exe"
              Name="ClientService.exe"
              Source="...\ClientService.exe"
              Vital="yes" KeyPath="yes" DiskId="1"/>
        <File Id="App.config"
              Name="App.config"
              Source="...\App.config"
              Vital="yes" KeyPath="no" DiskId="1"/>

            <!--And some DLLs here-->

        <ServiceInstall Id="ServiceInstaller"
                        Type="ownProcess"
                        Vital="yes"
                        Name="WcfServiceHost"
                        DisplayName="WcfServiceHost"
                        Description="Hosts Wcf Service"
                        Start="auto"
                        Account="LocalSystem"
                        ErrorControl="ignore"
                        Interactive="no">
        </ServiceInstall>
        <ServiceControl Id="StartService" Name="WcfServiceHost"
                        Start="install" Stop="uninstall" Remove="uninstall"
                        Wait="yes" />
      </Component>
    </DirectoryRef>

    <Feature Id="Complete" Title="SetupWinService" Level="1">
      <ComponentRef Id="WinServiceInstallation" />
      <ComponentGroupRef Id="Product.Generated" />
    </Feature>
  </Product>
</Wix>

I can install my service, but I can't start it after installing. It tells:

我可以安装我的服务,但是安装后我不能启动它。它告诉:

Service failed to start. Verify that you have sufficient privileges to start system services.

服务失败的开始。验证您有足够的权限启动系统服务。

But I run my installer as administrator (Windows 7 Professional) and also disable UAC. Furthermore, I can install and run the service with instalutil.exe through command prompt (my service project includes realization of Installer class and in general is marked up according to this article), and all works fine with the service in that case.

但我以管理员(Windows 7专业人员)的身份运行安装程序,同时禁用UAC。此外,我可以安装和运行该服务与instalutil。exe通过命令提示符(我的服务项目包括了安装程序类的实现,一般是按照本文的方式进行标记),在这种情况下,所有的服务都可以正常工作。

If I replace Wait="yes" of the ServiceControl element to "no", the service installs without errors, but it does not start. I also can't start the service manually in that case, because the service starts and immediately stops with message "service on Local Computer started and then stopped. Some services stop automatically if they have no work to do".

如果我将ServiceControl元素的Wait="yes"替换为"no",则该服务安装时不会出现错误,但它不会启动。在这种情况下,我也不能手动启动服务,因为服务启动并立即停止在本地计算机上的消息“服务启动,然后停止”。有些服务如果没有工作就会自动停止。

I searched about this problem on the Internet, but I didn't find any solutions.

我在网上搜索了这个问题,但没有找到任何解决办法。

How do I fix it?

我怎么修理它?

That is the code of my Installer class:

这是我的安装程序类的代码:

[RunInstaller(true)]
public class ProjectInstaller : Installer
{
    private ServiceProcessInstaller serviceProcessInstaller;
    private ServiceInstaller serviceInstaller;

    public ProjectInstaller()
    {
        this.serviceProcessInstaller = new ServiceProcessInstaller();
        this.serviceProcessInstaller.Account = ServiceAccount.LocalSystem;
        this.serviceProcessInstaller.Username = null;
        this.serviceProcessInstaller.Password = null;
        this.serviceInstaller = new ServiceInstaller();
        this.serviceInstaller.ServiceName = "ClientServicesHost";
        this.serviceInstaller.StartType = ServiceStartMode.Automatic;
        this.Installers.Add(serviceProcessInstaller);
        this.Installers.Add(serviceInstaller);
        this.AfterInstall +=
                new InstallEventHandler(ProjectInstaller_AfterInstall);
    }

    void ProjectInstaller_AfterInstall(object sender, InstallEventArgs e)
    {
        ServiceController sc = new ServiceController("ClientServicesHost");
        sc.Start();
    }
}

And my Windows service:

和我的Windows服务:

class WindowsClientService : ServiceBase
{
    public ServiceHost serviceHost = null;

    public WindowsClientService()
    {
        this.ServiceName = "WcfServiceHost";
    }

    public static void Main()
    {
        ServiceBase.Run(new WindowsClientService());
    }

    protected override void OnStart(string[] args)
    {
        if (serviceHost != null)
        {
            serviceHost.Close();
        }

        // Create a ServiceHost for WcfClientService type
        // and provide the base address.
        serviceHost = new ServiceHost(typeof(WcfClientService));

        // Open the ServiceHost to create listeners
        // and start listening for messages.
        serviceHost.Open();
    }

    protected override void OnStop()
    {
        if (serviceHost != null)
        {
            serviceHost.Close();
            serviceHost = null;
        }
    }
}

I was pointed out that the reason of my service automatically stops - it does nothing after start. Can it be? My service creates listeners and starts listening - is that "does nothing"?

我被指出,我的服务自动停止的原因——它在启动后什么都不做。它可以吗?我的服务创造了听众,开始倾听——那是“什么都不做”吗?

7 个解决方案

#1


5  

I had the same issue using WiX 3.7.821.0 and my service. It installed for a while and the same annoying "Service failed to start. Verify that you have sufficient privileges to start system services" appeared.

我使用的是WiX 3.7.821.0和我的服务。它安装了一段时间,同样烦人的“服务没有启动”。验证您有足够的特权启动系统服务。

I tried a lot, but the final thing was to use two sections for <ServiceControl> instead of trying to cram all in a single one. One for Start and one for Stop. Now the service starts fine.

我尝试了很多,但是最后一件事是使用两个部分来实现 ,而不是把所有的都塞进一个。一个开始,一个停止。现在服务开始了。

This does not work:

这并不工作:

<ServiceControl Id="StartService" 
                Start="install" 
                Stop="both" 
                Remove="uninstall" 
                Name="MyService" 
                Wait="yes" />

This works:

如此:

<ServiceControl Id="ServiceControl_Start"
                Name="MyService"
                Start="install"
                Wait="no" />
<ServiceControl Id="ServiceControl_Stop"
                Name="MyService"
                Stop="both"
                Remove="uninstall"
                Wait="yes" />

#2


4  

I had the same error, and in my case I was missing KeyPath='yes' Vital="yes" on my file element.

我有相同的错误,在我的例子中,我在文件元素上丢失了KeyPath='yes'的关键="yes"。

Here is my component definition:

以下是我的组件定义:

<Component Id="ComponentName"
           Guid="3aa1d5a5-28f0-4753-8e4b-a7ac0848d8be" >
    <File Id='ServiceFile'
          Name='Service.exe'
          DiskId='1'
          Source='bin\Service.exe'
          KeyPath='yes'
          Vital="yes"/>

    <ServiceInstall Id="ServiceInstaller"
                    Type="ownProcess"
                    Name="Service"
                    DisplayName="Service"
                    Description="A Service"
                    Start="auto"
                    ErrorControl="normal"
                    />

    <ServiceControl Id="ServiceControl"
                    Start="install"
                    Stop="both"
                    Remove="uninstall"
                    Name="Service"
                    Wait="yes" />
</Component>

#3


4  

I have been looking for the answer for a while, and finally I've resolved it!

我一直在寻找答案,最后终于解决了!

Keep the same ServiceControl name as the ServiceInstall name.

保持与ServiceInstall名称相同的ServiceControl名称。

Result:

结果:

<?xml version="1.0" encoding="utf-8"?>
<?define ProductVersion = "1.0.0"?>
<?define ProductUpgradeCode = "{E8DFD614-41F6-4592-AD7A-27EA8A49C82E}"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"
     xmlns:util="http://schemas.microsoft.com/wix/UtilExtension">
  <Product Id="*" UpgradeCode="$(var.ProductUpgradeCode)"
           Name="Eyes Relax"
           Version="$(var.ProductVersion)"
           Manufacturer="Ourdark"
           Language="1033">
    <Package Manufacturer="Ourdark" InstallerVersion="100" Languages="1033" Compressed="yes" />

    <Media Id="1" Cabinet="WHSDiskManagement.1.1.0.0.cab" EmbedCab="yes" />

    <Property Id="WHSLogo">1</Property>

    <Directory Id="TARGETDIR" Name="SourceDir">
      <Directory Id="ProgramFilesFolder" Name="PFiles">
        <Directory Id="WHS" Name="Eyes Relax">
          <Component Id="EyesRelax" Guid="{78534F5E-FC72-49E6-AF11-4F2068EA7571}">

            <File Id="RelaxEyes.exe.config"
                  Name="RelaxEyes.exe.config"
                  Source="RelaxEyes\bin\Debug\RelaxEyes.exe.config"
                  Vital="yes"
                  KeyPath="no"
                  DiskId="1"/>

            <File Id="RelaxEyes.exe"
                  Name="RelaxEyes.exe"
                  Source="RelaxEyes\bin\Debug\RelaxEyes.exe"
                  Vital="yes"
                  KeyPath="yes"
                  DiskId="1"/>

            <ServiceInstall
              Id="ServiceInstaller"
              Type="ownProcess"
              Vital="yes"
              Name="Eyes Relax"
              DisplayName="Eyes Relax"
              Description="Eyes Relax"
              Start="auto"
              Account="NT AUTHORITY\LocalService"
              ErrorControl="ignore"
              Interactive="no">
            </ServiceInstall>
            <ServiceControl Id="StartService"
                            Start="install"
                            Stop="both"
                            Remove="uninstall"
                            Name="Eyes Relax"
                            Wait="yes" />
          </Component>
        </Directory>
      </Directory>
    </Directory>

    <Feature Id="ProductFeature" Title="WHSDiskManagement" Level="1">
      <ComponentRef Id="EyesRelax" />
    </Feature>
  </Product>
</Wix>

#4


2  

The username for ServiceInstall should be fully qualified:

ServiceInstall的用户名应该完全限定:

NT AUTHORITY\NetworkService

NT AUTHORITY)\ NetworkService

NT AUTHORITY\LocalService

NT AUTHORITY)\ LocalService

NT AUTHORITY\SYSTEM

NT AUTHORITY)\系统

#5


2  

Well, I returned to this project after about 1 and half year. And trying to recompile it and start this service again. And it works!

大约一年半之后,我回到了这个项目。尝试重新编译并重新启动这个服务。和它的工作原理!

All that changed is I added clientaccesspolicy.xml to my service and run policyServiceHost (of type WebServiceHost) along with my service. But I don't think it is important because of it relates to insides of my application - not to service start.

改变的是我添加了clientaccesspolicy。xml到我的服务和运行policyServiceHost(类型WebServiceHost)和我的服务。但我认为这并不重要,因为它涉及到我的应用程序的内部——而不是服务启动。

So I tried many variations, like:

所以我尝试了很多变化,比如:

1) this.serviceProcessInstaller.Username = null;

1)this.serviceProcessInstaller。用户名=零;

or

this.serviceProcessInstaller.Username = @"NT AUTHORITY\SYSTEM";

this.serviceProcessInstaller。用户名= @“NT AUTHORITY)\系统”;

2) Two or single ServiceControl sections.

2)两个或单个ServiceControl区段。

3) Stop="both"

3)停止= "都"

or

Stop="uninstall"

停止=“卸载”

ALL WORKS FINE NOW!!!

现在都没问题! ! !

I don't know what is happening. I just leave it to some type of bug or something strange configuration of my system or whatever else that doesn't allow me to start my service automatically before. But now all worksfine.

我不知道发生了什么。我只是把它留给某种类型的bug或者一些奇怪的系统配置或者其他不允许我自动启动服务的东西。但是现在所有worksfine。

Another words, I didn't find out what was the reason of my service won't to start automatically. It was about "sufficient privileges" (see the first post) but it is not clear enough for me even now.

换句话说,我没有发现我的服务为什么不能自动启动。这是关于“足够的特权”(见第一个帖子),但对我来说现在还不够清楚。

Only one remark. If I use two ServiceControl sections while uninstalling the service, a warning window appears (Windows 7) and offer to close application (service) automatically and so on. So I just accept and service uninstalls well. But no warning windows appear if I use only one ServiceControl section as in my example in the first post. And again it is no relations to 1) and 3) points combination.

只有一个备注。如果在卸载服务时使用两个ServiceControl区段,会出现一个警告窗口(Windows 7),并自动提供关闭应用程序(服务)等。所以我只接受和服务不安装。但是,如果我在第一个帖子中只使用一个ServiceControl部分,则不会出现警告窗口。再一次,它与1)和3)点组合无关。

#6


1  

I'd use this snippet for the .wxs-file

我将为.wxs文件使用此代码段。

<?xml version="1.0" encoding="UTF-8"?>
<?define ProductVersion="1.0.0.0" ?>
<?define UpgradeCode="{YOURGUID}" ?>
<?define Manufacturer="SetupWinService" ?>
<?define ProductName="WcfServiceHost" ?>
<?define SkuName="WcfServiceHost" ?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
    <Product Id="*"
             Name="$(var.ProductName)"
             Language="1049"
             Version="$(var.ProductVersion)"
             Manufacturer="$(var.Manufacturer)"
             UpgradeCode="$(var.UpgradeCode)">
        <!-- do you really need 200? i'd try at least 301 -->
        <Package InstallerVersion="301"
                 Compressed="yes"
                 Languages="1049"
                 InstallPrivileges="elevated"
                 SummaryCodepage="1251"
                 Platform="x86" />
        <Media Id="1"
               Cabinet="$(var.SkuName).cab"
               EmbedCab="yes" />
        <Directory Id="TARGETDIR"
                   Name="SourceDir">
            <Directory Id="ProgramFilesFolder">
                <Directory Id="ProductDirectory"
                           Name="$(var.ProductName)" />
            </Directory>
        </Directory>
        <ComponentGroup Id="MainComponentGroup">
            <Component Directory="ProductDirectory">
                <File Name="$(var.**Project**.TargetFileName)"
                      Source="$(var.**Project**.TargetPath)"
                      KeyPath="yes"
                      Vital="yes" />
                <ServiceInstall Id="SeviceInstall"
                                Name="$(var.ProductName)"
                                DisplayName="$(var.ProductName)"
                                Type="ownProcess"
                                Interactive="no"
                                Start="auto"
                                Vital="yes"
                                ErrorControl="normal"
                                Account="LOCALSYSTEM">
                </ServiceInstall>
                <ServiceControl Id="ServiceControl_Start"
                                Name="$(var.ProductName)"
                                Start="install"
                                Wait="no" />
                <ServiceControl Id="ServiceControl_Stop"
                                Name="$(var.ProductName)"
                                Stop="both"
                                Remove="uninstall"
                                Wait="yes" />
            </Component>
            <Component Directory="ProductDirectory">
                <File Name="App.config"
                      Source="$(var.**Project**.TargetDir)\app.config"
                      Vital="yes" />
            </Component>
        </ComponentGroup>
        <Feature Id="MainFeature"
                 Level="1">
            <ComponentGroupRef Id="MainComponentGroup" />
        </Feature>
        <!-- added automatic upgrading -->
        <Upgrade Id="$(var.UpgradeCode)">
            <UpgradeVersion Property="UPGRADEFOUND"
                            Minimum="0.0.0.1" IncludeMinimum="yes"
                            Maximum="$(var.ProductVersion)" IncludeMaximum="yes"
                            OnlyDetect="no"
                            IgnoreRemoveFailure="yes"
                            MigrateFeatures="yes"/>
        </Upgrade>
        <InstallExecuteSequence>
            <InstallExecute Before="RemoveExistingProducts" />
            <RemoveExistingProducts Before="InstallFinalize" />
        </InstallExecuteSequence>
    </Product>
</Wix>

With this basic System.ServiceProcess.ServiceBase-implementation (which does not really differ from yours)

这个基本System.ServiceProcess。ServiceBase-implementation(它与您的不同)

public partial class Service : ServiceBase
{
    public Service()
    {
        this.InitializeComponent();
    }

    public static void Main()
    {
        Run(new Service());
    }

    #region Service Commands

    protected override void OnStart(string[] args)
    {
    }

    protected override void OnStop()
    {
    }

    protected override void OnPause()
    {
        this.OnStop();
    }

    #endregion
}

With this snippet I got a demo-project to work ...

有了这段代码,我得到了一个工作的demo项目。

Fully working demo project available - if this still fails, please adapt the code, so that I can reproduce your issue!

完整的演示项目可用-如果这仍然失败,请修改代码,以便我可以重现您的问题!

#7


0  

I had this error on some computers. The same executable works on some and gives this error on others.

我在一些电脑上犯了这个错误。同样的可执行文件在某些方面起作用,并在其他方面给出错误。

Updating .NET 1.1/2.0/3.0 on these computers helps (it worked for me on Windows XP, 7 and 8.1).

在这些计算机上更新. net 1.1/2.0/3.0有助于(在Windows XP、7和8.1中为我工作)。

#1


5  

I had the same issue using WiX 3.7.821.0 and my service. It installed for a while and the same annoying "Service failed to start. Verify that you have sufficient privileges to start system services" appeared.

我使用的是WiX 3.7.821.0和我的服务。它安装了一段时间,同样烦人的“服务没有启动”。验证您有足够的特权启动系统服务。

I tried a lot, but the final thing was to use two sections for <ServiceControl> instead of trying to cram all in a single one. One for Start and one for Stop. Now the service starts fine.

我尝试了很多,但是最后一件事是使用两个部分来实现 ,而不是把所有的都塞进一个。一个开始,一个停止。现在服务开始了。

This does not work:

这并不工作:

<ServiceControl Id="StartService" 
                Start="install" 
                Stop="both" 
                Remove="uninstall" 
                Name="MyService" 
                Wait="yes" />

This works:

如此:

<ServiceControl Id="ServiceControl_Start"
                Name="MyService"
                Start="install"
                Wait="no" />
<ServiceControl Id="ServiceControl_Stop"
                Name="MyService"
                Stop="both"
                Remove="uninstall"
                Wait="yes" />

#2


4  

I had the same error, and in my case I was missing KeyPath='yes' Vital="yes" on my file element.

我有相同的错误,在我的例子中,我在文件元素上丢失了KeyPath='yes'的关键="yes"。

Here is my component definition:

以下是我的组件定义:

<Component Id="ComponentName"
           Guid="3aa1d5a5-28f0-4753-8e4b-a7ac0848d8be" >
    <File Id='ServiceFile'
          Name='Service.exe'
          DiskId='1'
          Source='bin\Service.exe'
          KeyPath='yes'
          Vital="yes"/>

    <ServiceInstall Id="ServiceInstaller"
                    Type="ownProcess"
                    Name="Service"
                    DisplayName="Service"
                    Description="A Service"
                    Start="auto"
                    ErrorControl="normal"
                    />

    <ServiceControl Id="ServiceControl"
                    Start="install"
                    Stop="both"
                    Remove="uninstall"
                    Name="Service"
                    Wait="yes" />
</Component>

#3


4  

I have been looking for the answer for a while, and finally I've resolved it!

我一直在寻找答案,最后终于解决了!

Keep the same ServiceControl name as the ServiceInstall name.

保持与ServiceInstall名称相同的ServiceControl名称。

Result:

结果:

<?xml version="1.0" encoding="utf-8"?>
<?define ProductVersion = "1.0.0"?>
<?define ProductUpgradeCode = "{E8DFD614-41F6-4592-AD7A-27EA8A49C82E}"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"
     xmlns:util="http://schemas.microsoft.com/wix/UtilExtension">
  <Product Id="*" UpgradeCode="$(var.ProductUpgradeCode)"
           Name="Eyes Relax"
           Version="$(var.ProductVersion)"
           Manufacturer="Ourdark"
           Language="1033">
    <Package Manufacturer="Ourdark" InstallerVersion="100" Languages="1033" Compressed="yes" />

    <Media Id="1" Cabinet="WHSDiskManagement.1.1.0.0.cab" EmbedCab="yes" />

    <Property Id="WHSLogo">1</Property>

    <Directory Id="TARGETDIR" Name="SourceDir">
      <Directory Id="ProgramFilesFolder" Name="PFiles">
        <Directory Id="WHS" Name="Eyes Relax">
          <Component Id="EyesRelax" Guid="{78534F5E-FC72-49E6-AF11-4F2068EA7571}">

            <File Id="RelaxEyes.exe.config"
                  Name="RelaxEyes.exe.config"
                  Source="RelaxEyes\bin\Debug\RelaxEyes.exe.config"
                  Vital="yes"
                  KeyPath="no"
                  DiskId="1"/>

            <File Id="RelaxEyes.exe"
                  Name="RelaxEyes.exe"
                  Source="RelaxEyes\bin\Debug\RelaxEyes.exe"
                  Vital="yes"
                  KeyPath="yes"
                  DiskId="1"/>

            <ServiceInstall
              Id="ServiceInstaller"
              Type="ownProcess"
              Vital="yes"
              Name="Eyes Relax"
              DisplayName="Eyes Relax"
              Description="Eyes Relax"
              Start="auto"
              Account="NT AUTHORITY\LocalService"
              ErrorControl="ignore"
              Interactive="no">
            </ServiceInstall>
            <ServiceControl Id="StartService"
                            Start="install"
                            Stop="both"
                            Remove="uninstall"
                            Name="Eyes Relax"
                            Wait="yes" />
          </Component>
        </Directory>
      </Directory>
    </Directory>

    <Feature Id="ProductFeature" Title="WHSDiskManagement" Level="1">
      <ComponentRef Id="EyesRelax" />
    </Feature>
  </Product>
</Wix>

#4


2  

The username for ServiceInstall should be fully qualified:

ServiceInstall的用户名应该完全限定:

NT AUTHORITY\NetworkService

NT AUTHORITY)\ NetworkService

NT AUTHORITY\LocalService

NT AUTHORITY)\ LocalService

NT AUTHORITY\SYSTEM

NT AUTHORITY)\系统

#5


2  

Well, I returned to this project after about 1 and half year. And trying to recompile it and start this service again. And it works!

大约一年半之后,我回到了这个项目。尝试重新编译并重新启动这个服务。和它的工作原理!

All that changed is I added clientaccesspolicy.xml to my service and run policyServiceHost (of type WebServiceHost) along with my service. But I don't think it is important because of it relates to insides of my application - not to service start.

改变的是我添加了clientaccesspolicy。xml到我的服务和运行policyServiceHost(类型WebServiceHost)和我的服务。但我认为这并不重要,因为它涉及到我的应用程序的内部——而不是服务启动。

So I tried many variations, like:

所以我尝试了很多变化,比如:

1) this.serviceProcessInstaller.Username = null;

1)this.serviceProcessInstaller。用户名=零;

or

this.serviceProcessInstaller.Username = @"NT AUTHORITY\SYSTEM";

this.serviceProcessInstaller。用户名= @“NT AUTHORITY)\系统”;

2) Two or single ServiceControl sections.

2)两个或单个ServiceControl区段。

3) Stop="both"

3)停止= "都"

or

Stop="uninstall"

停止=“卸载”

ALL WORKS FINE NOW!!!

现在都没问题! ! !

I don't know what is happening. I just leave it to some type of bug or something strange configuration of my system or whatever else that doesn't allow me to start my service automatically before. But now all worksfine.

我不知道发生了什么。我只是把它留给某种类型的bug或者一些奇怪的系统配置或者其他不允许我自动启动服务的东西。但是现在所有worksfine。

Another words, I didn't find out what was the reason of my service won't to start automatically. It was about "sufficient privileges" (see the first post) but it is not clear enough for me even now.

换句话说,我没有发现我的服务为什么不能自动启动。这是关于“足够的特权”(见第一个帖子),但对我来说现在还不够清楚。

Only one remark. If I use two ServiceControl sections while uninstalling the service, a warning window appears (Windows 7) and offer to close application (service) automatically and so on. So I just accept and service uninstalls well. But no warning windows appear if I use only one ServiceControl section as in my example in the first post. And again it is no relations to 1) and 3) points combination.

只有一个备注。如果在卸载服务时使用两个ServiceControl区段,会出现一个警告窗口(Windows 7),并自动提供关闭应用程序(服务)等。所以我只接受和服务不安装。但是,如果我在第一个帖子中只使用一个ServiceControl部分,则不会出现警告窗口。再一次,它与1)和3)点组合无关。

#6


1  

I'd use this snippet for the .wxs-file

我将为.wxs文件使用此代码段。

<?xml version="1.0" encoding="UTF-8"?>
<?define ProductVersion="1.0.0.0" ?>
<?define UpgradeCode="{YOURGUID}" ?>
<?define Manufacturer="SetupWinService" ?>
<?define ProductName="WcfServiceHost" ?>
<?define SkuName="WcfServiceHost" ?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
    <Product Id="*"
             Name="$(var.ProductName)"
             Language="1049"
             Version="$(var.ProductVersion)"
             Manufacturer="$(var.Manufacturer)"
             UpgradeCode="$(var.UpgradeCode)">
        <!-- do you really need 200? i'd try at least 301 -->
        <Package InstallerVersion="301"
                 Compressed="yes"
                 Languages="1049"
                 InstallPrivileges="elevated"
                 SummaryCodepage="1251"
                 Platform="x86" />
        <Media Id="1"
               Cabinet="$(var.SkuName).cab"
               EmbedCab="yes" />
        <Directory Id="TARGETDIR"
                   Name="SourceDir">
            <Directory Id="ProgramFilesFolder">
                <Directory Id="ProductDirectory"
                           Name="$(var.ProductName)" />
            </Directory>
        </Directory>
        <ComponentGroup Id="MainComponentGroup">
            <Component Directory="ProductDirectory">
                <File Name="$(var.**Project**.TargetFileName)"
                      Source="$(var.**Project**.TargetPath)"
                      KeyPath="yes"
                      Vital="yes" />
                <ServiceInstall Id="SeviceInstall"
                                Name="$(var.ProductName)"
                                DisplayName="$(var.ProductName)"
                                Type="ownProcess"
                                Interactive="no"
                                Start="auto"
                                Vital="yes"
                                ErrorControl="normal"
                                Account="LOCALSYSTEM">
                </ServiceInstall>
                <ServiceControl Id="ServiceControl_Start"
                                Name="$(var.ProductName)"
                                Start="install"
                                Wait="no" />
                <ServiceControl Id="ServiceControl_Stop"
                                Name="$(var.ProductName)"
                                Stop="both"
                                Remove="uninstall"
                                Wait="yes" />
            </Component>
            <Component Directory="ProductDirectory">
                <File Name="App.config"
                      Source="$(var.**Project**.TargetDir)\app.config"
                      Vital="yes" />
            </Component>
        </ComponentGroup>
        <Feature Id="MainFeature"
                 Level="1">
            <ComponentGroupRef Id="MainComponentGroup" />
        </Feature>
        <!-- added automatic upgrading -->
        <Upgrade Id="$(var.UpgradeCode)">
            <UpgradeVersion Property="UPGRADEFOUND"
                            Minimum="0.0.0.1" IncludeMinimum="yes"
                            Maximum="$(var.ProductVersion)" IncludeMaximum="yes"
                            OnlyDetect="no"
                            IgnoreRemoveFailure="yes"
                            MigrateFeatures="yes"/>
        </Upgrade>
        <InstallExecuteSequence>
            <InstallExecute Before="RemoveExistingProducts" />
            <RemoveExistingProducts Before="InstallFinalize" />
        </InstallExecuteSequence>
    </Product>
</Wix>

With this basic System.ServiceProcess.ServiceBase-implementation (which does not really differ from yours)

这个基本System.ServiceProcess。ServiceBase-implementation(它与您的不同)

public partial class Service : ServiceBase
{
    public Service()
    {
        this.InitializeComponent();
    }

    public static void Main()
    {
        Run(new Service());
    }

    #region Service Commands

    protected override void OnStart(string[] args)
    {
    }

    protected override void OnStop()
    {
    }

    protected override void OnPause()
    {
        this.OnStop();
    }

    #endregion
}

With this snippet I got a demo-project to work ...

有了这段代码,我得到了一个工作的demo项目。

Fully working demo project available - if this still fails, please adapt the code, so that I can reproduce your issue!

完整的演示项目可用-如果这仍然失败,请修改代码,以便我可以重现您的问题!

#7


0  

I had this error on some computers. The same executable works on some and gives this error on others.

我在一些电脑上犯了这个错误。同样的可执行文件在某些方面起作用,并在其他方面给出错误。

Updating .NET 1.1/2.0/3.0 on these computers helps (it worked for me on Windows XP, 7 and 8.1).

在这些计算机上更新. net 1.1/2.0/3.0有助于(在Windows XP、7和8.1中为我工作)。