簡體   English   中英

如何從應用程序訪問MSI公共屬性?

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

我通過javafxpackager使用Wix為Java(8)應用程序構建MSI安裝程序。 安裝它時,我可以傳遞命令行屬性,例如:

msiexec /i app.msi FOO=BAR

如何從自己的應用程序訪問FOO的值?

我已經有一個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>

您可以在安裝過程中將任何公共屬性(UPPERCASE)寫入注冊表,然后可以使用常規注冊表訪問機制(無論開發語言所支持的結構)在運行時從應用程序中讀取該值。

屬性不會自動保存到注冊表中,您需要自己將它們添加到注冊表中。 也許看看WiX工具集的“記住屬性”模式

您需要添加:

<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訪問它的各種方法可以找到: 使用Java讀/寫Windows注冊表。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM