Reputation: 1368
I'm building a WiX installer where I want to do a registry search for the install directory for a 3rd party application. The 3rd party application I'm interested in creates a registry entry under HKLM which points not only to the install directory, but it also includes the file name and extension (ie. C:/Program Files/MyApp/myapp.exe). What I need is just the actual parent directory (ie. C:/Program Files/MyApp) so that when I do a Directory/File search it looks in the correct location. Is there a way to modify the @Property that gets returned from the registry search to only include the parent directory and strip out the file name and extension? Here's what I have:
<Property Id="MYAPPINSTALLFOLDER">
<RegistrySearch Id='InstallPathRegistry'
Type='raw'
Root='HKLM'
Key='SOFTWARE\Company\SomeLongPath'
Name='FileName'
Win64='yes'/>
</Property>
<Property Id="ISINSTALLED">
<DirectorySearch Id="CheckFileDir" Path="[MYAPPINSTALLFOLDER]" Depth="0">
<FileSearch Id="CheckFile" Name="myapp.exe" />
</DirectorySearch>
</Property>
Upvotes: 0
Views: 258
Reputation: 631
Create a separate class in which you can add your own Custom Actions:
public static class InstallCustomActions
{
[CustomAction]
public static ActionResult GetDirectoryFromPath(Session session)
{
string fullPath = session["MYAPPINSTALLFOLDER"];
session["MYAPPINSTALLFOLDER"] = Path.GetDirectoryName(fullPath); //You can also create a separate property. In that case I would rename MYAPPINSTALLFOLDER to MYAPPFULLPATH.
}
}
Then you declare your CustomAction (either in your Product.wxs or in a separate .wxi file):
<CustomAction Id="GetDirectoryFromPath"
BinaryKey="PROJECTNAMEHERE"
DllEntry="GetDirectoryFromPath"
Execute="immediate"
Return="check" />
And then you can call it in your UISequence for example:
<Publish Dialog="MyDlg" Control="Next" Event="DoAction" Value="GetDirectoryFromPath" Order="1">1</Publish>
If anything is unclear, let me know. This is based on a working project but I have not tested this specific code after altering it to match your request.
Upvotes: 0