Replicate Behavior of a Batch File in a Custom Action

旧时模样 提交于 2020-01-07 03:40:55

问题


I'm creating a wix installer at work, and I need to be able to replicate the behavior of this batch file in a custom action:

start /d "C:\Program Files (x86)\Remindex" INSTSRV.EXE RemindexNP 
"C:\Program Files (x86)\Remindex\SRVANY.EXE"

I am trying to create a service using a normal windows application, which SRVANY.EXE can do. This batch file runs fine normally, but I can't seem to get a custom action to do the same thing. I have tried this:

<CustomAction Id="RunNP" FileKey="FILE_INSTALLFOLDER_INSTSRVEXE" 
              ExeCommand="RemindexNP [INSTALLFOLDER]SRVANY.EXE" Execute="commit" Return="ignore"/>

This custom action doesn't cause any errors that I can see in the log file, but I don't think instsrv.exe is accepting the parameters I'm passing in ExeCommand. I know that instsrv.exe and srvany.exe exist because I'm running the custom action before InstallFinalize.

Anyone know what's wrong with my custom action?

I would prefer not to include an actual batch file in my install folder, as it would have no reason to be there besides being run on install. I have tried including one in the installer, but I don't know how to reference the install directory. When I use %cd%, it just references the system folder for some reason.

I tried using ServiceInstall and ServiceControl elements, but the installer gets stuck on "starting services". Here is my component:

<Component Id="CMP_RemindexNP.exe" Guid="{3FB99890-752D-4652-9412-72230695A520}">
    <File Id="FILE_INSTALLFOLDER_RemindexNPEXE" Source="RemindexNP.exe" KeyPath="yes"/>
        <RegistryKey Root="HKLM" Key="SYSTEM\CurrentControlSet\Services\RemindexNP\Parameters">
          <RegistryValue Id="rg_remNP1" Action="write" Name="AppDirectory" Value="[INSTALLFOLDER]" Type="string"/>
          <RegistryValue Id="rg_remNP2" Action="write" Name="Application" Value="[INSTALLFOLDER]RemindexNP.exe" Type="string"/>
        </RegistryKey>
        <ServiceInstall DisplayName="RemindexNP" Id="srv_remNP" Name="RemindexNP" Start="auto" Type="shareProcess" ErrorControl="ignore"/>
        <ServiceControl Id="srvc_remNP" Name="RemindexNP" Remove="both" Start="install" Stop="uninstall" Wait="no"/>
      </Component>

And my log:

Action 17:15:08: StartServices. Starting services
Action start 17:15:08: StartServices.
StartServices: Service: Starting services
Action ended 17:15:08: StartServices. Return value 1.

Any suggestions would be greatly appreciated.


回答1:


This is a trick question as you don't need a custom action. The srvany.exe acts as a service host and as such can be authored into your installer using the Directory, Component, File, ServiceInstall and (if desired) ServiceControl elements.



来源:https://stackoverflow.com/questions/18495579/replicate-behavior-of-a-batch-file-in-a-custom-action

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!