简体   繁体   中英

my C# windows application runs on system startup. but works in windows xp and not in windows 7. I have written these codes

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);
}

First of all, be aware that registry keys are different for 32-bit and 64-bit systems. Also, in case your application is not running with admin rights, it is probably not permitted to write registry keys.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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