如何从应用程序访问MSI公共属性? [英] How do I access MSI public properties from my application?
问题描述
我正在通过javafxpackager使用Wix为Java(8)应用程序构建MSI安装程序.安装它时,我可以传递命令行属性,例如:
I'm using Wix via javafxpackager to build an MSI installer for my Java (8) app. When installing it, I can pass command line attributes, such as:
msiexec /i app.msi FOO=BAR
如何从自己的应用程序访问FOO
的值?
How do I go about accessing the value of FOO
from my own application?
我已经有一个自定义的wxs
文件,javafxpackager正在拾取该文件(src/main/deploy/package/windows/<<APPNAME>>.wxs
),看起来像这样
I already have a custom wxs
file that javafxpackager is picking up (src/main/deploy/package/windows/<<APPNAME>>.wxs
) and it looks like this
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"
xmlns:util="http://schemas.microsoft.com/wix/UtilExtension">
<Product Id="PRODUCT_GUID" Name="APPLICATION_NAME"
Language="1033" Version="APPLICATION_VERSION"
Manufacturer="APPLICATION_VENDOR"
UpgradeCode="PUT-GUID-HERE">
<Package Description="APPLICATION_DESCRIPTION" Comments="None"
InstallerVersion="200" Compressed="yes"
InstallScope="INSTALL_SCOPE" Platform="PLATFORM"/>
<Media Id="1" Cabinet="simple.cab" EmbedCab="yes"/>
<!-- We use RemoveFolderEx to ensure application folder is fully
removed on uninstall. Including files created outside of MSI
after application had been installed (e.g. on AU or user state).
Hovewer, RemoveFolderEx is only available in WiX 3.6,
we will comment it out if we running older WiX.
RemoveFolderEx requires that we "remember" the path for uninstall.
Read the path value and set the APPLICATIONFOLDER property with the value.
-->
<Property Id="APPLICATIONFOLDER">
<RegistrySearch Key="SOFTWARE\APPLICATION_VENDOR\APPLICATION_NAME"
Root="REGISTRY_ROOT" Type="raw"
Id="APPLICATIONFOLDER_REGSEARCH" Name="Path"/>
</Property>
<DirectoryRef Id="APPLICATIONFOLDER">
<Component Id="CleanupMainApplicationFolder" Guid="*" Win64="WIN64">
<RegistryValue Root="REGISTRY_ROOT"
Key="SOFTWARE\APPLICATION_VENDOR\APPLICATION_NAME"
Name="Path" Type="string" Value="[APPLICATIONFOLDER]"
KeyPath="yes"/>
<!-- We need to use APPLICATIONFOLDER variable here or RemoveFolderEx
will not remove on "install". But only if WiX 3.6 is used. -->
WIX36_ONLY_START
<util:RemoveFolderEx On="uninstall" Property="APPLICATIONFOLDER"/>
WIX36_ONLY_END
</Component>
</DirectoryRef>
<?include bundle.wxi ?>
UI_BLOCK
APP_CDS_BLOCK
<Icon Id="DesktopIcon.exe" SourceFile="APPLICATION_ICON"/>
<Icon Id="StartMenuIcon.exe" SourceFile="APPLICATION_ICON"/>
SECONDARY_LAUNCHER_ICONS
<MajorUpgrade Schedule="afterInstallInitialize"
DowngradeErrorMessage="A later version of this app is already installed. Setup will now exit."/>
<Icon Id="icon.ico" SourceFile="app.ico"/>
<Property Id="ARPPRODUCTICON" Value="icon.ico"/>
</Product>
</Wix>
推荐答案
您可以在安装过程中将任何公共属性(UPPERCASE)写入注册表,然后可以使用常规注册表访问权在运行时从应用程序中读取该值.机制(无论构建您的开发语言支持什么).
You can write any public property (UPPERCASE) to the registry during your installation, and then you can read back that value from your application at runtime using regular registry access mechanisms (whatever constructs your development language supports).
属性不会自动保存到注册表中,您需要自己将它们添加到注册表中.也许请查看 WiX工具集的记住财产"模式.
Properties are not automatically persisted to the registry, you need to add them to the registry yourself. Perhaps check out The WiX toolset's "Remember Property" pattern.
您需要添加:
<RegistryValue Root="HKLM"
Key="SOFTWARE\APPLICATION_VENDOR\APPLICATION_NAME"
Name="Foo" Type="string" Value="[FOO]"/>
和
<Property Id="FOO">
<RegistrySearch Id="Foo"
Root="HKLM"
Key="SOFTWARE\APPLICATION_VENDOR\APPLICATION_NAME"
Name="Foo" Type="raw"/>
</Property>
到.wxs
文件.这样可以将属性记录在注册表中,并在升级时重新保存.
to the .wxs
file. That will take care of recording the property in the registry and re-saving it when upgrading.
可以通过以下方式找到从Java访问它的各种方法:读/写Java使用Windows注册表
Various methods from accessing it from Java can be found on: read/write to Windows Registry using Java
这篇关于如何从应用程序访问MSI公共属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!