3

i am writing a win app and now i want to make setup for my app,my code is:

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

now how can get the path from installer to set it??? thanks.

Farna
  • 1,157
  • 6
  • 26
  • 45
  • Hmmm. Why do you need to create Registry entries manually? Use Visual Studio to create a new "Setup Project"; it will automatically handle the nitty-gritty stuff involved in installing your application to the end user's computer. – Cody Gray - on strike Mar 07 '11 at 08:43

2 Answers2

2

If you use Visual Studio, you can right click on the setup project -> View -> Registry and then set the registry key you like.

Check out this sites:

msi - Set InstallPath registry key

Registry Settings Management (MSDN)

Community
  • 1
  • 1
swissben
  • 1,059
  • 8
  • 13
  • i make registry key in this way "setup project -> View -> Registry and then set the registry key you like." but now how can set value when it become install?i mean i want to get path from user and then set . – Farna Mar 11 '11 at 11:03
  • sorry for very delayed answer! you can add a custom action which calls an exe-file that reads the path and put it into registry. go to Setup Project -> View -> Custom Actions -> select Install and Add Custom Action adding the exe-file. – swissben Mar 21 '11 at 08:08
0

If it was installed using Windows Installer (.MSI files), you can use the MsiGetComponentPath API:

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

Call it like this:

int len = 256;
StringBuilder sb = new StringBuilder(len);
MsiGetComponentPath(productCode, componentId, sb, ref len);
Simon Mourier
  • 132,049
  • 21
  • 248
  • 298