简体   繁体   English

如何从应用程序访问MSI公共属性?

[英]How do I access MSI public properties from my application?

I'm using Wix via javafxpackager to build an MSI installer for my Java (8) app. 我通过javafxpackager使用Wix为Java(8)应用程序构建MSI安装程序。 When installing it, I can pass command line attributes, such as: 安装它时,我可以传递命令行属性,例如:

msiexec /i app.msi FOO=BAR

How do I go about accessing the value of FOO from my own application? 如何从自己的应用程序访问FOO的值?

I already have a custom wxs file that javafxpackager is picking up ( src/main/deploy/package/windows/<<APPNAME>>.wxs ) and it looks like this 我已经有一个javafxpackager可以拾取的自定义wxs文件( 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>

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). 您可以在安装过程中将任何公共属性(UPPERCASE)写入注册表,然后可以使用常规注册表访问机制(无论开发语言所支持的结构)在运行时从应用程序中读取该值。

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 . 也许看看WiX工具集的“记住属性”模式

You need to add: 您需要添加:

<RegistryValue Root="HKLM" 
               Key="SOFTWARE\APPLICATION_VENDOR\APPLICATION_NAME"                                
               Name="Foo" Type="string" Value="[FOO]"/>

and

<Property Id="FOO">
    <RegistrySearch Id="Foo"
                    Root="HKLM"
                    Key="SOFTWARE\APPLICATION_VENDOR\APPLICATION_NAME"
                    Name="Foo" Type="raw"/>
</Property>

to the .wxs file. .wxs文件。 That will take care of recording the property in the registry and re-saving it when upgrading. 这样可以将属性记录在注册表中,并在升级时重新保存它。

Various methods from accessing it from Java can be found on: read/write to Windows Registry using Java 从Java访问它的各种方法可以找到: 使用Java读/写Windows注册表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从Java应用程序内部获取公共IPV6地址? - How do I get my public IPV6 address from inside my Java Application? 如何从视图访问数据或应用程序模型? - How do I access the data, or model of my application from the view? Java:如何访问我的属性文件? - Java: How do I access my properties file? 如何在 SoapUI 中从 API 访问属性 - How do I access properties from API in SoapUI 如何从 Testcontainer 的应用程序文件加载属性? - How do I load properties from application file for Testcontainer? 如何从我的应用程序中的 androidTest(插桩测试)测试类访问资源? - How do I access resources from my application inside of an androidTest (instrumented test) test class? 如何使用MSI从Java向Azure存储进行身份验证? - How do I authenticate to Azure Storage from Java using MSI? 如何使用从@PropertySource 中提取的属性 - How do I use my exctracted properties from @PropertySource 如何在Spring Boot应用程序中使用配置(properties / yml)文件中的属性? - How can I use properties from a configuration (properties/yml) file in my Spring Boot application? 如何从 Java 应用程序中的另一个类访问在实用程序类中声明的公共最终静态列表? - How can I access to a public final static list declared into an utility class from another class in a Java application?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM