2011-08-15 129 views
1

我正在爲可以作爲主程序的一部分安裝或單獨安裝的實用程序進行安裝。主程序在註冊表項中的位置。如果安裝了主程序,該實用程序應安裝在「Utilities」子目錄中。例如D:\ Program Files(x86)\ MainProgram \ Utilities。如果主程序沒有安裝,那麼它應該默認爲根驅動器文件夾,例如C:\ Program Files(x86)\ MainProgram \ Utilities。根據條件更改安裝位置

安裝應該得到註冊表項(例如HKLM \ Software \ MainProgram \ Key:「Install_location」)。這將提供一個路徑,直到d:\ Program File(x86)\ MainProgram。該實用程序應該直接安裝在其子目錄中。如果密鑰不存在,它應該默認爲標準位置。

回答

1

使用C#或某種其他語言從自定義操作中讀取註冊表值,並檢查密鑰是否存在,否則可以使用WIX查找是否存在註冊表項。

RegistryKey regKey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"Software\MainProgram\Key"); 

if ((string)Registry.GetValue(regKey, "Install_location", "0") != "0") 
{ 
    session["Somevariable"] = (string)Registry.GetValue(regKey, "Install_location") 
} 

使用WIX

<Property Id="INSTALLLOCATION"> 
     <RegistrySearch Id="INSTALLLOCATION" 
       Name="Install_location" 
       Root="HKLM" 
       Key="Software\MainProgram\Key" 
       Type="raw" /> 
</Property> 

在維克斯會話變量的值的基礎上,你可以決定安裝位置,並在所需的路徑安裝該實用程序。

1

閱讀MainProgram(主程序)的位置到屬性:

<Property Id="MainProgramDir"> 
    <RegistrySearch Id="FindMainProgramDir" 
       Root="HKLM" 
       Key="Software\MainProgram" 
       Name="Install_location" 
       Type="directory" /> 
</Property> 

並設置目錄結構的默認行爲:

<Directory Id="TARGETDIR" Name="SourceDir"> 
    <Directory Id="ProgramFilesFolder"> 
    <Directory Id="MainProgramDir" Name="MainProgram"> 
     <Directory Id="INSTALLDIR" Name="Utilities"/> 
    </Directory> 
    </Directory> 
</Directory> 

目錄元素是一樣的屬性,如果有將被覆蓋具有相同Id的財產。如果該屬性未設置(因爲RegistrySearch失敗),那麼它將如您在設置的目錄結構中定義的那樣。

+0

感謝它的工作.... –

+0

想要嘗試回答這個問題嗎? http://stackoverflow.com/questions/19355537/wix-setting-install-folder-correctly –