【发布时间】:2011-05-26 03:16:38
【问题描述】:
我得到以下代码在 Windows 启动时运行应用程序:
private void SetStartup(string AppName, bool enable)
{
string runKey = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run";
Microsoft.Win32.RegistryKey startupKey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(runKey);
if (enable)
{
if (startupKey.GetValue(AppName) == null)
{
startupKey.Close();
startupKey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(runKey, true);
startupKey.SetValue(AppName, Application.ExecutablePath.ToString());
startupKey.Close();
}
}
else
{
startupKey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(runKey, true);
startupKey.DeleteValue(AppName, false);
startupKey.Close();
}
}
它有效。但我希望程序最小化启动(仅在 Windows 启动时)。 我没有找到有效的代码/很好的解释如何做到这一点。 你能帮帮我吗?
谢谢。
【问题讨论】:
-
我在 2019 年 1 月的今天发现了这个问题,Ron 提出的子程序今天仍然有效,稍作修改:startupKey=Registry.CurrentUser.OpenSubKey(runKey) 谢谢您的子程序。简短而简单。