Run wpf application on windows startup

I developed a WPF application, now I have to start the application when Windows starts.
For this, I wrote the code below. I got a solution from this answer .
It adds the key to the registry, but does not start the application.

Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
string str = Assembly.GetExecutingAssembly().Location;
key.SetValue("Camaleone", str);
+4
source share
2 answers

When you usually start the application by double-clicking, the working directory is usually an EXE file. This means that if you link to any configuration files in your code, they can find them.

But when you add it to the registry to start at startup, the working directory c:\windows\system32, because it is launched by the windows themselves.

:

public static string BaseDir = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);

, BaseDir - exe.

, , , , :

string mySettingsFile = Path.Combine(BaseDir, "MySettingsFile.xml");
+4

, . .

0

Source: https://habr.com/ru/post/1523666/


All Articles