简体   繁体   English

C#-Windows启动时的Properties.Settings.Default

[英]C# - Properties.Settings.Default on Windows Startup

I have a C# program that runs on startup via an entry in SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run . 我有一个C#程序,该程序通过SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run的条目在启动时SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run On startup, it seems that it can't read Whatever.exe.config (Settings file). 在启动时,似乎无法读取Whatever.exe.config (设置文件)。

I'm aware that the "current dir" on boot is somewhere in %windir% . 我知道引导时的“当前目录”位于%windir% At the moment, I'm trying to load the config file by concatenating the config file name and Application.ExecutablePath , but I'm not sure how to implement that. 目前,我正在尝试通过连接配置文件名和Application.ExecutablePath来加载配置文件,但是我不确定如何实现。

How do I use Properties.Settings.Default on Windows Startup? 如何在Windows启动时使用Properties.Settings.Default

EDIT: I'm on HKCU. 编辑:我在HKCU上。 I'm using Registry.CurrentUser.OpenSubKey("SOFTWARE\\\\Microsoft\\\\Windows\\\\CurrentVersion\\\\Run", true); 我正在使用Registry.CurrentUser.OpenSubKey("SOFTWARE\\\\Microsoft\\\\Windows\\\\CurrentVersion\\\\Run", true);

Do not load the file yourself and leave the paths alone ! 不要自己加载该文件,不要理会路径

The Microsoft .NET settings mechanism does it all for you. Microsoft .NET设置机制可以为您完成所有操作。 The settings file will be automatically read when the application starts. 应用程序启动时将自动读取设置文件。 And the user settings will be read from the user's profile. 用户设置将从用户配置文件中读取。

What you didn't say is whether the application start through a user's registry entry (HKCU) or through the machine (HKLM). 您没有说的是应用程序是通过用户的注册表项(HKCU)还是通过计算机(HKLM)启动的。 If you have user settings, they will be looked for in the current user's directory. 如果您具有用户设置,则将在当前用户的目录中查找它们。 That means that things may not work as expected when running the application with no used logged in. 这意味着在不使用任何未登录状态下运行该应用程序时,事情可能无法按预期进行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM