Note that there are some explanatory texts on larger screens.

plurals
  1. POWeird behavior with windows startup C#
    primarykey
    data
    text
    <p>I've created an application with the option to start on Windows startup. First I did this via the Registry, like this:</p> <pre><code>private void RunOnStartup(bool RunOnStartup) { Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true); if (RunOnStartup) { key.SetValue(ProgramTitle, System.Windows.Forms.Application.ExecutablePath.ToString()); } else { key.DeleteValue(ProgramTitle, false); } } </code></pre> <p>And this worked, but not correctly. It started the .exe but with the same behavior as it was a new one with the default 'config.xml' it needs. Which is obviously wrong.</p> <p>I did not manage to find out what was wrong, so I tried it differently: create a shortcut in the Startup folder. Couldn't go wrong I figured, I mean, it's just a shortcut right?</p> <p>I used this code:</p> <pre><code>private void RunOnStartup(bool RunOnStartup) { string startup = Environment.GetFolderPath(Environment.SpecialFolder.Startup) + "\\"+ProgramTitle+".url"; if (RunOnStartup) { using (StreamWriter writer = new StreamWriter(startup)) { string app = System.Reflection.Assembly.GetExecutingAssembly().Location; writer.WriteLine("[InternetShortcut]"); writer.WriteLine("URL=file:///" + app); writer.WriteLine("IconIndex=0"); string icon = app.Replace('\\', '/'); writer.WriteLine("IconFile=" + icon); writer.Flush(); } } else { if (File.Exists(startup)) { File.Delete(startup); } } } </code></pre> <p>And this worked as well, it started, but with the same behavior.</p> <p>So my question is, does anyone have any idea how this happens? Any help is much appreciated!</p> <p>Thanks</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload