views:

237

answers:

1

I have an application that is deployed with ClickOnce, and has an option to automatically start with Windows. However, when I restart Windows, my application starts successfully, but is not able to find the settings (I'm just using the built-in Settings functionality). However, if I close the auto-started app and restart it with the icon on the desktop, it is able to find it's settings.

To start automatically with Windows, I'm using the following code:

Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
if (runOnStartup == true) 
    key.SetValue("AppName", Application.ExecutablePath.ToString());
else 
    key.DeleteValue("AppName");

I noticed that the desktop shortcut doesn't point directly to an exe, but rather a url like:

http://pathToApp.application#AppName.application, Culture=neutral, PublicKeyToken=c8c0a22ba65cb9f4, processorArchitecture=x86

How can I get my auto-start app to work the same way as the shortcut does?

+1  A: 

You don't have control over where a ClickOnce app gets installed and it will move any time it's upgraded, so I don't store settings that can change in the app.config file. Instead I create my own settings file (usually using a simple xml serialized object) to a "known" folder, such as Environment.SpecialFolder.CommonApplicationData or Environment.SpecialFolder.LocalApplicationData

Jim Harte
I should also mention that I deploy using the "offline" install mode. You might be limited to where you can write to if you used the "online only" mode.
Jim Harte