2

我寫一個雙贏的應用程序,現在我想讓設置爲我的應用程序,我的代碼是:如何從安裝程序獲取路徑以及如何在我的應用程序中設置?

Microsoft.Win32.RegistryKey rk = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\Cu­rrentVersion\Run"); 
rk.SetValue("MyAppName", @"C:\WhereMyAppIs\MyApp.exe"); 

現在如何從安裝程序獲取路徑設置它??? 謝謝。

+0

嗯。爲什麼需要手動創建註冊表項?使用Visual Studio創建一個新的「安裝項目」;它會自動處理涉及將應用程序安裝到最終用戶計算機中的細節問題。 – 2011-03-07 08:43:58

回答

2

如果您使用Visual Studio,你可以右鍵單擊安裝項目 - >查看 - >註冊表,然後設置您喜歡的註冊表項。

看看這個網站:

msi - Set InstallPath registry key

Registry Settings Management (MSDN)

+0

我無法解決我的問題/ – Farna 2011-03-11 11:01:40

+0

我以這種方式創建註冊表項「setup project - > View - > Registry,然後設置你喜歡的註冊表項。」但現在如何設置值,當它成爲安裝?我的意思是我想從用戶獲得路徑,然後設置。 – Farna 2011-03-11 11:03:30

+0

非常遲到的答案!您可以添加一個自定義操作,它調用一個讀取路徑並將其放入註冊表的exe文件。轉到安裝項目 - >查看 - >自定義操作 - >選擇安裝並添加自定義操作添加exe文件。 – swissben 2011-03-21 08:08:13

0

如果是使用Windows Installer(.MSI文件)安裝,你可以使用MsiGetComponentPath API:

[DllImport("msi.dll", CharSet = CharSet.Unicode)] 
    private static extern int MsiGetComponentPath(string szProduct, string szComponent, StringBuilder lpPathBuf, ref int pcchBuf); 

這樣稱呼它:

int len = 256; 
StringBuilder sb = new StringBuilder(len); 
MsiGetComponentPath(productCode, componentId, sb, ref len); 
+0

@Simon Mourier:我想在安裝我的安裝文件時設置註冊表項,但我不知道如何從用戶獲取路徑,然後設置註冊表的值鍵。 – Farna 2011-03-07 08:58:34

+0

@ na.farzane - 你使用Windows安裝程序嗎? – 2011-03-07 09:42:23

+0

@Simon Mourier:我使用Visual Studio。 – Farna 2011-03-07 10:04:30

相關問題