title: Set that a program has to run at startup from an installer
body: <p>I've a C# .net 4 application, I'm starting to create the installer.</p>
  
  <p>The installed program works fine, but my customer want that the application start with window(it's an "Always of top" toolbar which help them to manage their call).</p>
  
  <p>I thought to create a "Class Installer", and in it insert a key in the registry.</p>
  
  <p>I've two problems:</p>
  
  <p>First: How can I find the executable path? It can change between installation. I found somewhere a Application.ExecutablePath, but it seems it located into Application.Window.Forms so I think its not compatible with WPF</p>
  
  <p>Second: I need to insert this key in the registry of the local machine. Is there a way in a windows installer to specify that the user must have admin rights?</p>
  
  <p>Here is the code I started:</p>
  
  <pre><code>RegistryKey rkApp = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
  rkApp.SetValue("CstStart", ???);
  </code></pre>
  
  <p>Thank you very much for your help!</p>
  
  <p>EDIT: I found that I can pass to my Custom action some data, with : </p>
  
  <blockquote>
    <p>/DIR="[TARGETDIR]\"</p>
  </blockquote>
  
  <p>in the CustomActionData.</p>
  
  <p>Normally it's said I can retrieve it through the </p>
  
  <pre><code>this.Context.Parameters["DIR"];
  </code></pre>
  
  <p>But.... it seems that in my installer class, this.Context is null :(</p>
  
  <p>EDIT2: The Context was null because I was doing this in the constructor, I'm now doing this in the event this.AfterInstall and now I get a context, which seems to contains a var "assemblypath" which contains exactly the path I need.</p>