Wix installer to replace INSTSRV and SRVANY for us

2020-01-29 01:25发布

I created an executable MyService.exe using Visual Studio C# Express. There are no options in the Express version to create a service. In the past, this has been manually installed as a user defined service using the INSTSRV and SRVANY as described in the MSDN Article 'How To Create a User-Defined Service'

Is it possible to create a wix 3.5 installer for this file that

  1. doesn't require the existence of the SRVANY.exe and INSTRV.exe files on the target machine
  2. does not use INSTSRV.exe as a custom action

2条回答
Root(大扎)
2楼-- · 2020-01-29 01:42

WiX does support installing Windows services, but only native ones. This means that the application must be written as a service.

Since your application uses SRVANY.EXE to run as a service, you have two options

  • rewrite your application as a native Windows service

or

  • use custom actions to execute the SRVANY.EXE and INSTSRV.EXE command lines
查看更多
看我几分像从前
3楼-- · 2020-01-29 01:55

Here's the real scoop: A service is a service is a service. That's my motto. What I mean by that is I don't care if you are using a C++ EXE, a VB exe, a C# EXE, some thunking host EXE such as SrvAny.exe... they all implement the same API's to interact with the service control manager.

So SrvAny is going to get invoked by the SCM and get a start command. At that point it's going to read the registry values and know how to run your other EXE or script. When SrvAny gets Stop call it's going to terminate your process and report stopped to the SCM.

So that's how a service runs. Let's talk about how to install it. There are a great many ways you could programmatically create the service (SC, InstSrv.exe, Installer Class Custom Actions and so on) but from an MSI perspective none of them are ever needed. The Windows Installer has the ServiceInstall and ServiceControl tables along with standard actions to handle starting, stopping, creating and removing Windows Services. Occassionally, such as the case with SrvAny.exe, you get some installer requirements that can't be expressed using those tables and in that case you use the Registry table. For SrvAny.exe that's the requirement to create a Parameters key with registry data that teaches SrvAny.exe what to actually call when it starts.

Here's a sample in WiX for using SrvAny.exe to run a NodeJs script as a service:

<Component Id="c1" Guid="redacted">
  <File Id="f1" Source="$(var.SourceDir)\srvany.exe" KeyPath="yes" />
  <ServiceInstall Id="si1" DisplayName="MyService" Description="MyService" Name="MyService" Start="auto" Type="ownProcess" Vital="no" ErrorControl="normal" Account="NT AUTHORITY\NetworkService"  />
  <ServiceControl Id="sc1" Name="MyService" Remove="both" Stop="both" Start="install" Wait="yes" />
  <RegistryValue Id="reg1" Root="HKLM" Key="SYSTEM\CurrentControlSet\Services\MyService\Parameters" Name="Application" Type="string" Value="node &quot;[#f2]&quot;" Action="write" />
</Component>
<Component Id="c2" Guid="redacted" KeyPath="yes">
  <File Id="f2" Source="$(var.SourceDir)\server.js" />
</Component>
查看更多
登录 后发表回答