gpt4 book ai didi

java - 如何从我的应用程序访问 MSI 公共(public)属性?

转载 作者:行者123 更新时间:2023-12-02 11:28:31 25 4
gpt4 key购买 nike

我正在通过 javafxpackager 使用 Wix 为我的 Java (8) 应用程序构建 MSI 安装程序。安装时,我可以传递命令行属性,例如:

msiexec /i app.msi FOO=BAR

如何访问 FOO 的值来 self 自己的应用程序?

我已经有一个自定义wxs javafxpackager 正在拾取的文件 ( src/main/deploy/package/windows/<<APPNAME>>.wxs ),它看起来像这样

<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>

最佳答案

您可以在安装过程中将任何公共(public)属性(大写)写入注册表,然后您可以在运行时使用常规注册表访问机制(无论您的开发语言支持什么构造)从应用程序中读回该值。

属性不会自动保存到注册表中,您需要自己将它们添加到注册表中。也许看看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 文件。这将负责在注册表中记录属性并在升级时重新保存它。

可以在以下位置找到从 Java 访问它的各种方法:read/write to Windows Registry using Java

关于java - 如何从我的应用程序访问 MSI 公共(public)属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49457079/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com