簡體   English   中英

無法在MSI安裝程序的自定義操作中編寫注冊表

[英]Unable to write registry in custom action of MSI installer

我有一個MSI安裝程序,用於安裝Windows Service,並且在我的自定義操作中,我需要在HKEY_LOCAL_MACHINE/SOFTWARE/MYSoftware項中向注冊表中寫入一些值。

我正在嘗試執行此操作,但它不起作用,但是從我的Windows Service中可以正常工作。 誰能告訴我我要去哪里錯了?

string registryLocaltion = AgentProperties.TMAGENT_REGISTRY_LOCATION
                           + @"\" +AgentProperties.TMAgentVersion;

tmKeyMain = Registry.LocalMachine.OpenSubKey(registryLocaltion, true);
if (tmKeyMain == null)
{
    log.Error("Unable to open registry key " + registryLocaltion);
}

tmKeyMain.SetValue("UseProxySettings", settings.UseProxySettings);
if (settings.UseProxySettings)
{
    tmKeyMain.SetValue("ProxyHost", settings.ProxyHost);
    tmKeyMain.SetValue("ProxyPort", settings.ProxyPort);
    tmKeyMain.SetValue("ProxyUsername",
              GenericHelper.ConvertToBase64Encoding(settings.ProxyUsername));
    tmKeyMain.SetValue("ProxyPassword",
              GenericHelper.ConvertToBase64Encoding(settings.ProxyPassword));
    tmKeyMain.SetValue("ProxyExclusion", settings.ProxyExclusion);
    tmKeyMain.SetValue("BypassProxy", settings.BypassProxy);
}

該代碼在Windows服務中可以正常工作,但是如果我在MSI安裝程序中的自定義操作中執行了一些非常相似的操作,則該代碼將無效。

誰能告訴我我要去哪里錯了?

您遇到了幾個問題。 最明顯的問題是Visual Studio部署項目錯誤地安排了自定義操作來模擬客戶端上下文。 這意味着在UAC方案中,您將沒有權限。 快速解決方法是從已經提升的命令提示符上下文中運行MSI。

第二個問題是Visual Studio部署項目過多地抽象/隱藏了底層MSI。 對於“自定義操作”,它僅提供“安裝,卸載,回滾,提交”選項,而沒有公開任何其他設置。 它隱藏了ServiceInstall和ServiceControl表。 這會使您編寫自定義動作,從而重新構造了輪子。

看,您所有的自定義操作應該執行的是執行業務邏輯和設置屬性。 然后,您應該使用注冊表表根據屬性設置數據。 這樣,您可以盡可能多地利用Windows Installer及其所有免費的事務處理/回滾功能。

這個問題一遍又一遍地重復,這就是為什么Microsoft在VS2012中取消了安裝項目類型的原因。

如果是我的安裝,我將重構設計,以使用AppSearch / Reglocator讀取數據,執行極簡主義的自定義操作來進行處理,然后使用注冊表表來應用數據。

這至少需要您查看Windows Installer XML來創建具有所有這些邏輯並被合並到現有安裝項目中的合並模塊。 不過,這需要一段時間才能學會。

暫無
暫無

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

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