Create DSN with Wix - wix

Having trouble making a System DSN via Wix
here is my test code
<?xml version="1.0" encoding="utf-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Product Id="*" Name="TestProduct" Language="1033" Version="0.0.0.1" Manufacturer="WixEdit" UpgradeCode="*">
<Package Description="Test file in a Product" Comments="Simple test" InstallerVersion="200" Compressed="yes" />
<Media Id="1" Cabinet="simple.cab" EmbedCab="yes" />
<Directory Id="TARGETDIR" Name="SourceDir">
<Component Id="C_PROD_DSN" Guid="*">
<ODBCDataSource Id="Prod_Dsn" Name="SomeName" Registration="machine" DriverName="ODBC Driver 11 for SQL Server">
<Property Id="Description" Value="Some Description" />
<Property Id="Database" Value="SomeDB" />
<Property Id="Language" Value="us_english" />
<Property Id="LastUser" Value="SomeUser" />
<Property Id="Driver" Value="C:\windows\system32\msodbcsql11.dll" />
</ODBCDataSource>
</Component>
</Directory>
<Feature Id="DefaultFeature" Title="Main Feature" Level="1">
<ComponentRef Id="C_PROD_DSN" />
</Feature>
<UI />
</Product>
</Wix>
Wix Edit compiles it just fine but when i run it I get
Error configuring ODBC data source: SomeName. ODBC error 6: Component not found in the registry. Verify that the file SomeName exists and that you can access it.
This is a DSN to a SQL DB not to a file.
I know I can make this work by just building up the Registry trees I need, I just like to try it using what should be the built in functionality for the task.
Can this be done using ODBCDataSource? (without Custom Actions, I just don't have time to write another one right now) or should I just cut my losses and do it with RegistryKey and RegistryValue?

Related

WiX - protect the registry value when upgrade an application

I have a wix based setup (MSI) and want to protect user settings, which are stored in the registry under HKCU, when updating my application.
For now, when I upgrade my application every registry value will be overwritten, so that the user has to set his settings again.
I also want to remove all settings, when uninstall the whole application.
Can anybody help?
My code looks like this:
<Component Id="REGISTRY_ReConnect" Guid="$(var.GUID_REGISTRY_ReConnect)">
<RegistryValue Id="_REGISTRY_ReConnect" Root="HKCU" Key="Software\exampleX\MBCA" Name="ReConnect" Value="1" Type="integer" KeyPath="yes" />
</Component>
For each of the settings in registry do the following:
Define a Property containing the default value of the setting.
Define a RegistrySearch which will extract a value of the setting from registry and put it into another Property.
Use SetProperty to (conditionally) upgrade the value of first property with the value extracted from the registry.
In your Component/RegistryValue/#Value use the value of the first property instead of explicit value.
<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Product Id="*" Name="MyProduct" Language="1033" Version="1.1.0.0" Manufacturer="MyCompany" UpgradeCode="81a34cee-f0da-4135-9f37-53e02e4b450a">
<Package InstallerVersion="200" Compressed="yes" InstallScope="perUser" />
<MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
<Media Id="1" />
<Feature Id="ProductFeature" Title="MyProduct1" Level="1">
<ComponentGroupRef Id="ProductComponents" />
</Feature>
</Product>
<Fragment>
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolde">
<Directory Id="INSTALLFOLDER" Name="MyProduct" />
</Directory>
</Directory>
</Fragment>
<Fragment>
<Property Id="ReConnect" Value="1" />
<Property Id="OLDRECONNECT">
<RegistrySearch Id="ReConnectSearch" Root="HKCU" Key="Software\exampleX\MBCA" Name="ReConnect" Type="raw" />
</Property>
<SetProperty Id="ReConnect" Value="[OLDRECONNECT]" After="AppSearch">OLDRECONNECT</SetProperty>
<ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER">
<Component Id="REGISTRY_ReConnect">
<RegistryValue Id="_REGISTRY_ReConnect" Root="HKCU" Key="Software\exampleX\MBCA" Name="ReConnect" Value="[ReConnect]" Type="integer" KeyPath="yes" />
</Component>
</ComponentGroup>
</Fragment>
</Wix>

WiX: Register app to autorun when Windows is launches doesn't work

I'm trying to register app to autorun when Windows is launches. I can't understand why it doesn't work?
I'm trying to do that:
<!-- Files.wxs -->
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"
xmlns:fw="http://schemas.microsoft.com/wix/FirewallExtension"> <Fragment>
<DirectoryRef Id="INSTALLLOCATION"
FileSource="..\MyApp\bin\Release\">
<Component Id ="ProductComponents"
DiskId="1"
Guid="{482A3E9A-8FCA-44C6-96C5-F7B026DF85C4}">
<File Id="MyApp.exe.config" Name="MyApp.exe.config"/>
<File Id="MyApp.exe" Name="MyApp.exe"/>
<RegistryKey
Root="HKLM"
Key="Software\Microsoft\Windows\CurrentVersion\Run">
<RegistryValue Id="MyApp.exe" Name="MyApp" Value="[INSTALLLOCATION]MyApp.exe" Type="string" />
</RegistryKey>
</Component>
</DirectoryRef>
</Fragment>
</Wix>
<!-- Product.wxs -->
<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<?include Variables.wxi?>
<Product Id="*"
Name="$(var.ProductName)"
Language="1033"
Version="$(var.Version)"
Manufacturer="$(var.Manufacturer)"
UpgradeCode="MY_GUID">
<Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" />
<WixVariable Id="WixUILicenseRtf" Value="eula.rtf" />
<Media Id="1" Cabinet="media1.cab" EmbedCab="yes" />
<MajorUpgrade
AllowDowngrades="no"
DowngradeErrorMessage="New version is already installed."
AllowSameVersionUpgrades="no"
Schedule="afterInstallInitialize"/>
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder">
<Directory Id="INSTALLLOCATION" Name="MyApp" />
</Directory>
</Directory>
<Feature Id="ProductFeature" Title="MyApp" Level="1">
<ComponentRef Id="ProductComponents" />
</Feature>
<Property Id="WIXUI_INSTALLDIR" Value="INSTALLLOCATION"></Property>
<UIRef Id="WixUI_InstallDir"/>
<CustomAction Id="LaunchApp" Directory="INSTALLLOCATION" ExeCommand="[SystemFolder]cmd.exe /C start MyApp.exe" />
<InstallExecuteSequence>
<Custom Action="LaunchApp" After="InstallFinalize">NOT Installed AND NOT REMOVE</Custom>
</InstallExecuteSequence>
</Product>
</Wix>
I want to achieve auto start myApp.
The most likely issue is that it needs elevation and therefore will be blocked by UAC:
https://blogs.msdn.microsoft.com/uac/2006/08/23/elevations-are-now-blocked-in-the-users-logon-path/
and:
Program needing elevation in Startup registry key (windows 7)
If it's not that, then check that the path in the registry Run key is actually correct (in the 32-bit or 64-bit registry).
Entries in the Run key do not run "when Windows is launched". They start when the user logs on. If you really want something to run when Windows starts you need a service or a Task Scheduler entry that starts when Windows starts.

Why Wix MSI doesn't include the source files and looks for source files somewhere else?

I have used Wix on and off for almost a year. After a little break and now I am back to wix and need to build a wix Msi again but I found a very strange thing that I haven't met before. After I created the msi file and and copy the msi to somewhere to install. During the installation, it shows an error that it can't find the source files from the folder: current msi location\EasyLobby\Cogito. I was wondering why it tried to find the source files from that location. I then found that from the project during the compilation, it always creates \EasyLobby\Cogito under the bin\Debug folder. So if I run the msi right from the ...bin\Debug, it runs OK because the \EasyLobby\Cogito folder is there. \
It seems so strange. The msi file should include all the source files and shouldn't look for source files somewhere else. Here is the product.wxs file:
<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Product Id="*" Name="SetupCogito" Language="1033" Version="2.0.0.0" Manufacturer="Microsoft" UpgradeCode="96cb03c9-6a03-4344-b816-20a0bb9e5df0">
<Package InstallerVersion="200" Compressed="no" InstallScope="perMachine" />
<MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
<Media Id="1" Cabinet="Server.cab" EmbedCab="yes" />
<!--<MediaTemplate />-->
<Feature Id="ProductFeature" Title="SetupCogito" Level="1">
<ComponentGroupRef Id="ComponentGroup"/>
<ComponentRef Id="EasyLobbyCogitoShortcut" />
</Feature>
<WixVariable Id="WixUILicenseRtf" Value="Files\LicenseAgmt.rtf"/>
<UIRef Id="CogitoUI_Installdir" />
<Property Id="WIXUI_INSTALLDIR" Value="COGITOFOLDER" />
<Binary Id="banner_bmp" SourceFile="Files\Banner.bmp"/>
<Property Id ="PIDTemplate" >
<![CDATA[&&&-&&&&&&-&&&&-&&&&]]>
</Property>
<Icon Id="ELCogitoConfig.exe" SourceFile="..\CogitoIntegration\ELCogitoConfig.exe" />
</Product>
<Fragment>
<Binary Id="CustomActions"
SourceFile="..\CustomActions\bin\Debug\CustomActions.CA.dll" />
<CustomAction Id="IsValidKeyCode"
BinaryKey="CustomActions"
DllEntry="IsValidKeyCode"
Execute="immediate"
Return="check" />
<InstallExecuteSequence>
<Custom Action="IsValidKeyCode"
Before='InstallFinalize'>NOT Installed</Custom>
</InstallExecuteSequence>
</Fragment>
<Fragment>
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder">
<Directory Id="INSTALLFOLDER" Name="EasyLobby" >
<Directory Id="COGITOFOLDER" Name="Cogito"/>
</Directory>
</Directory>
<Directory Id="ProgramMenuFolder">
<Directory Id="ApplicationProgramsFolder" Name="EasyLobby Cogito" />
</Directory>
</Directory>
</Fragment>
<Fragment>
<DirectoryRef Id="COGITOFOLDER">
<Component Id="EasyLobbyCogitoShortcut" Guid="{BFE6EB30-0F71-4F92-8D93-84B4EBF41F0E}" >
<File Id="Easy" Source="$(var.SourceDir)\ELCogitoConfig.exe" />
<Shortcut Id="ApplicationStartMenuShortcut" Name="Cogito Configuration" Directory="ApplicationProgramsFolder"
WorkingDirectory='INSTALLDIR' Icon="ELCogitoConfig.exe" IconIndex="0" Advertise="yes"/>
</Component>
</DirectoryRef>
And this is the config for heat in project file:
<Target Name="BeforeBuild">
<PropertyGroup>
<DefineConstants>SourceDir= C:\Development\SetupCogito\CogitoIntegration;</DefineConstants>
<LinkerBaseInputPaths>..\CogitoIntegration\</LinkerBaseInputPaths>
</PropertyGroup>
<HeatDirectory OutputFile="CogitoSetup.wxs" Directory="..\CogitoIntegration" PreprocessorVariable="var.SourceDir" DirectoryRefId="COGITOFOLDER" ComponentGroupName="ComponentGroup" SuppressCom="true" SuppressFragments="true" SuppressRegistry="true" SuppressRootDirectory="true" AutoGenerateGuids="false" GenerateGuidsNow="true" ToolPath="$(WixToolPath)" />
This line here is your problem:
<Package InstallerVersion="200" Compressed="no" InstallScope="perMachine" />
Change Compressed=no to Compressed=yes and it will include all the source files in the finished MSI. If you don't compress it, the finished files are not included in the MSI and you get an error if it can't find them at runtime.
See Package reference.

wix: re-start an existing Service when install/uninstall finish

I would like to re-start a running service when my installer finish installing or uninstalling.
I have found this code:
<ServiceControl Id="SomeUniqueId" Name="NameOfTheirService"
Start="both" Stop="both"/>
But where do i attach this code to ?
to the component where my is placed ?
Code:
<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Product Id="325c4bfd-6614-43e9-aedb-93661295352d" Name="Plugin" Language="1033" Version="1.0.0.0"
Manufacturer="XXX Inc." UpgradeCode="4307526e-3902-40d0-991b-bacff9b3d71b">
<Package InstallerVersion="200" Compressed="yes" />
<Media Id="1" Cabinet="media1.cab" EmbedCab="yes" />
<Property Id="XXXXXX">
<RegistrySearch Id="XXXXXX" Type="raw"
Root="HKLM" Key="SOFTWARE\XXX\XXX" Name="InstallationPath" />
</Property>
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="XXXXXX">
<Component Id="ProductComponent" Guid="93118c45-f0c0-4c9e-9168-8ea905e9427c">
<File Id="pluggin" Source="C://setup.log" KeyPath="yes" Checksum="yes"/>
<ServiceControl Id="StartService" Name="servicename"
Start="both" Stop="both"/>
</Component>
</Directory>
</Directory>
<Feature Id="ProductFeature" Title="install" Level="1">
<ComponentRef Id="ProductComponent" />
<ComponentGroupRef Id="Product.Generated" />
</Feature>
</Product>
The ServiceControl element must be placed in a component that you install. From the WiX .chm:
Starts, stops, and removes services for parent Component. This element is used to control the state of a service installed by the MSI or MSM file by using the start, stop and remove attributes. For example, Start='install' Stop='both' Remove='uninstall' would mean: start the service on install, remove the service when the product is uninstalled, and stop the service both on install and uninstall.

Confused with Wix bootstraper

I am having trouble understanding wix documentation. I have created a simple installer that allows user to select a destination folder for app. It looks something like this:
<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Product Id="*" Name="AppName" Language="1033" Version="1.0.0.0" Manufacturer="Manufacturer" UpgradeCode="guid">
<Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" />
<MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
<MediaTemplate />
<Feature Id="ProductFeature" Title="SetupProjectFeature" Level="1">
<ComponentGroupRef Id="ProductComponents" />
</Feature>
<Property Id="WIXUI_INSTALLDIR" Value="INSTALLFOLDER" />
<UIRef Id="WixUI_InstallDir"/>
</Product>
<Fragment>
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder">
<Directory Id="INSTALLFOLDER" Name="OeeCoach" />
</Directory>
</Directory>
</Fragment>
<Fragment>
<ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER">
<!-- TODO: Insert files, registry keys, and other resources here. -->
<Component Id="EntityFramework" Guid="guid">
<File Id="EntityFramework.dll" Source="../App/bin/Release/EntityFramework.dll" KeyPath="yes" />
</Component>
<Component Id="MvvmLight.Extras" Guid="guid">
<File Id="GalaSoft.MvvmLight.Extras.WPF4.dll" Source="../App/bin/Release/GalaSoft.MvvmLight.Extras.WPF4.dll" KeyPath="yes" />
</Component>
</ComponentGroup>
</Fragment>
</Wix>
Now I need to check for .net 4 and its prerequisites, but I could not understand hot to do this. Documentation says that I need to use Bundle element, but compiler seems to complain when it is together with Product element in same wix file.
Any help is appreciated.
The bootstrapper is a separate project from your setup project. If you are using Visual Studio, add a new project to your solution and choose Bootstrapper project (instead of Setup project).