How to change the Windows service startup type in a WiX installer - windows

We need to modify the Startup type of our Windows service from "Automatic" to "Automatic Delayed Start". How do I do this?
My code is like this:
<ServiceInstall
Id="WinServiceInstall"
Name="ServiceManager"
DisplayName="ServiceManager"
Type="ownProcess"
Start="auto"
ErrorControl="normal"
Vital ='yes'
Description ='Monitoring and running the jobs'
Account="[SERVICEACCOUNT]"
Password="[SERVICEPASSWORD]">
<util:ServiceConfig
FirstFailureActionType="restart"
SecondFailureActionType="restart"
ThirdFailureActionType ="restart"
cRestartServiceDelayInSeconds ="10" />
</ServiceInstall>
And how do I set the Restart service time? I would like to set Restart service after 2 minutes if failed.

Place a ServiceConfig element within the ServiceInstall element.
<ServiceConfig DelayedAutoStart="yes" OnInstall="yes" OnReinstall ="yes" />

If you need to support really old versions of Windows, then you will need to set it with a reg-value, because MSI < 5.0 doesn't recognize this option with ServiceConfig. Otherwise, you should use the ServiceConfig method.
<RegistryValue Root="HKLM" Key="SYSTEM\CurrentControlSet\Services\[ServiceName]"
Type="integer" Name="DelayedAutostart" Value="1"/>
I put this in the same component as the ServiceInstall, and everything seems to work fine. I imagine you could do the same thing for the service restart time.

Related

MsiPackage conditional install: Don't uninstall if it detects package is already installed

I'm using Wix Bootstrapper and want to install a few applications through .msi packages alongside my main application. These applications may be installed in the target PC already so I need to detect these first and skip installation if they are already installed. Furthermore, during uninstallation, these applications should not be uninstalled since the Wix Bootstrapper did not install them.
I've tried to use the InstallCondition attribute but (as expected) it uninstalls if it detects the application is already installed.
My Bundle.wxs looks like this:
...
<Bundle>
<util:FileSearch Id='CheckApplicationX' Path='[ProgramFilesFolder]ApplicationX\ApplicationX.exe' Variable='ApplicationXFile' Result='exists' />
<Chain DisableRollback="yes">
...
<MsiPackage Id="InstallApplicationX" Vital="yes" Compressed="yes" DisplayInternalUI="no" EnableFeatureSelection="no" SourceFile="..\application-x.msi" Name="Application X" DisplayName="Application X" ForcePerMachine="yes" InstallCondition="NOT ApplicationXFile" />
...
</Chain>
</Bundle>
...
Any help/hints are appreciated!
You can try to detect if the applications are installed by looking in the Windows Registry and try to identify if there are "traces" left by those applications.
You can use the RegistrySearch tag to perform a conditional evaluation of the registry entries you're looking for and then deny the installation.
There's an example on Wix Website available at this link.
The following example shows how you can define if .NET 2.0 is installed on the target machine
<Property Id="NETFRAMEWORK20">
<RegistrySearch Id="NetFramework20"
Root="HKLM"
Key="Software\Microsoft\NET Framework Setup\NDP\v2.0.50727"
Name="Install"
Type="raw" />
</Property>
<Condition Message="This application requires .NET Framework 2.0. Please install the .NET Framework then run this installer again.">
<![CDATA[Installed OR NETFRAMEWORK20]]>
</Condition>

Wix : Declare or set property after ResolveSource

I try to search a file in my project. The problem is I use the var "SourceDir" and it's work fine in install with UI but no with silent install.
I found it's because SourceDir is not setted before I try to used it in silent mode.
That's why I want to set my property after the "ResolveSource" action
<Property Id='CUSTOMCONFIGFILEEXISTS'>
<DirectorySearch Id='DirSearch' Path='[SOURCEDIR]' Depth='0'>
<FileSearch Id='FileSearch' Name='EasyFolderApplicationDesktopToolbar.exe.config'/>
</DirectorySearch>
</Property>
...
<Component Id="CustomMainExecutableConfig" Guid="A952C40B-0274-4EA8-8A48-0216395455CF" Directory="INSTALLDIR" NeverOverwrite="yes">
<Condition>CUSTOMCONFIGFILEEXISTS</Condition>
<CopyFile Id="CustomEasyFolderApplicationDesktopToolbarCONFIG" SourceProperty="CUSTOMCONFIGFILEEXISTS" DestinationProperty="INSTALLDIR" />
<!--<CopyFile Id="CustomEasyFolderApplicationDesktopToolbarCONFIG" SourceProperty="CONFIGFILEEXISTS" DestinationProperty="INSTALLDIR" />-->
</Component>
I already try this, with no result :
<Property Id='CUSTOMCONFIGFILEEXISTS'>
<DirectorySearch Id='DirSearch' Path='[Temp]' Depth='0'>
<FileSearch Id='FileSearch' Name='EasyFolderApplicationDesktopToolbar.exe.config'/>
</DirectorySearch>
</Property>
<CustomAction Id='SET_CUSTOMCONFIGFILEEXISTS'
Property='Temp'
Value='[SourceDir]'/>
...
<InstallExecuteSequence>
<ResolveSource After="CostInitialize" ></ResolveSource>
<Custom Action='SET_CUSTOMCONFIGFILEEXISTS' After='ResolveSource'></Custom>
<Custom Action="AlreadyUpdated" After="FindRelatedProducts">SELFFOUND</Custom>
<Custom Action="NoDowngrade" After="FindRelatedProducts">NEWERFOUND</Custom>
<RemoveExistingProducts After="InstallExecute" />
</InstallExecuteSequence>
I already see this How do I use the SourceDir MSI property in WiX?
But I don't know how to do...
Can you help me ?
That search is ultimately an AppSearch, and in a WiX-built MSI that's the first thing that runs, so your 'CUSTOMCONFIGFILEEXISTS' property has already been processed by the search, so it's false by the time that component results in the component not being installed and the copyfile not being done. So the reason for the failure is not ResolveSource - it's because 'CUSTOMCONFIGFILEEXISTS' is being set false and you are conditioning the component and the copyfile on that false condition.
IMO you are over-thinking this. Don't bother with a search. Just pick a component relevant to the file you want to copy (don't invent a transitional component for it with a condition). Add the CopyFile to that component with [SourceDir] as the source. If the file is there it will be copied, if not then it won't be.
Don't add an unconditional ResolveSource action because it will happen every time the an installer action takes place (repair, removing features, patches, uninstall) and that is generally unnecessary. In any case I am certain you do not need a ResolveSource. There is an implicit ResolveSource at first install or it wouldn't even know where the MSI was! Just do the copyfile as I suggested.

Executing an EXE file in WiX

I try to execute an EXE file from an MSI file in WiX, but I got 1603 error when doing InitializeSetup.
Action ended 12:09:54: InstallValidate. Return value 1.
Action start 12:09:54: InstallInitialize.
Action ended 12:09:54: InstallInitialize. Return value 3.
Action ended 12:09:54: INSTALL. Return value 3.
What is wrong in this WiX Script?
<Product Name='something' Id='11934d63-12d1-4792-829e-046de3bb987e'
UpgradeCode='{a101616a-365c-44a7-bfcb-fafb356c2ea1}'
Language='1033' Version='8.3.4' Manufacturer='something2'>
<Package Id='*' InstallerVersion='200' Compressed='yes' />
<Binary Id="Instalator.exe" SourceFile="d:\Instalator.exe"/>
<CustomAction Id="LaunchFile" BinaryKey="Instalator.exe" ExeCommand="" Execute='deferred' Return='asyncNoWait' Impersonate='no'/>
<InstallExecuteSequence>
<Custom Action='LaunchFile' Before='InstallFinalize'/>
</InstallExecuteSequence>
</Product>
I don't know why, but when I add:
<Directory Id='TARGETDIR' Name='SourceDir'>
<Component Id='MainExecutable' Guid='1193cd63-12d1-4792-829e-046de3bb987e'>
</Component>
</Directory>
<Feature Id='Complete' Level='1'>
<ComponentRef Id='MainExecutable' />
</Feature>
after Package node -> then it works fine. I need to figure out why...
I have some other concerns about what you are doing here, but if you really need to go out of process to an EXE to complete your install, then I'd suggest using the Quiet Execution Custom Action.
You should know though that this isn't a good practice for a number of reasons. 1) It's not declarative, 2) it doesn't support rollbacks. There are others but those are the biggest IMO.
BTW, WiX isn't "scripting". Understand that and you'll understand why not to call EXE's.
Because you are running the exe as a deferred action, it runs in the context of the SYSTEM account. This error is due to the system account not having the required permissions on the file system http://support.microsoft.com/kb/834484.
It is possible to get around this using PowerShell to execute the exe using the -RunAs switch, but this is a bit nasty. It really all depends exactly what you are doing in the exe as to the best course of action. I'm with Mr. Painter, using an EXE should be the last resort.
Another option is to move the exe setup code so that it runs the first time the user runs the app.
Important note for WIX, After completion of all application installation then the .sql file or database files runs through wix or wpf or winform application.

WIX public properties displayed on the UI

We have an installer created using WIX. As part of this install we would like to show the currently selected installation path. I thought this would be much easier than it is, apparently. I have tried using the a public property "INSTALLDIR" (I know we're not using Installshield, this value is a directory ID.)
<Directory Id="INSTALLDIR" Name="AcmeInc">
I can also see where INSTALLDIR gets set when running the install
MSI(EC:6C) Dir (target): Key: INSTALLDIR , Object: C:\Program Files\AcmeInc\
but when I try to show this on the UI using a Text attribute I get "...\." which doesn't even look to be a relative path.
I know there has got to be something simple I'm missing here.
Assuming you're using WiX 3.5 and the MajorUpgrade element - the following should work (I usually use APPLICATIONFOLDER instead of INSTALLDIR - but they should be interchangeable).
First, let's set ARPINSTALLOCATION as described on http://robmensching.com/blog/posts/2011/1/14/ARPINSTALLLOCATION-and-how-to-set-it-with-the-WiX-toolset
<SetProperty Id="ARPINSTALLLOCATION" Value="[INSTALLDIR]" After="CostFinalize" />
Now lets set the selected installation folder to the previous installation folder, if one previously existed that is.
<Property Id="INSTALLDIR" Secure="yes">
<RegistrySearch Id="FindInstallLocation"
Root="HKLM"
Key="Software\Microsoft\Windows\CurrentVersion\Uninstall\[WIX_UPGRADE_DETECTED]"
Name="InstallLocation"
Type="raw"
Win64="yes" />
</Property>
And during the UI sequence, we want this value to be set 'early'
<InstallUISequence>
<AppSearch After="FindRelatedProducts"/>
</InstallUISequence>

Dynamically Set WixUIBannerBmp Location Based on Property

I have the following:
<WixVariable Id="WixUIBannerBmp" Value="FirstBanner.jpg" />
I want to be able to set the value of this WixVariable using a property that gets passed in when the installer is kicked off:
msiexec.exe /i MyInstaller.msi /l* install.log MYPROPERTY=SomeValue
So, based on the the value of MYPROPERTY, I set the value of the WixVariable to one of two (or more) values.
My initial stab at this proved unsuccessful:
<Property Id="BANNERLOCATION" Value="FirstBanner.jpg" />
<WixVariable Id="WixUIBannerBmp" Value="[BANNERLOCATION]" />
I get the following build error:
error LGHT0103: The system cannot find the file '[BANNERLOCATION]'.
Is what I am trying to achieve possible? This is simply branding the install based on a passed-in property, after all ...
No, what you are trying to accomplish is not supported by the Windows Installer. Sorry.

Resources