RegistryKey rkStartUp = Registry.CurrentUser;
RegistryKey StartupPath;
StartupPath =rkStartUp.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run", true);
if (StartupPath.GetValue("MyApplication") == null)
{
StartupPath.SetValue("MyApplication", Application.ExecutablePath, RegistryValueKind.ExpandString);
}
else
{
StartupPath.DeleteValue("MyApplication", true);
}
答案 0 :(得分:2)
首先,请注意32位和64位系统的注册表项不同。此外,如果您的应用程序未以管理员权限运行,则可能不允许编写注册表项。