在我的应用程序中,我试图通过使用以下代码添加注册表项来将我的应用程序设置为启动:
RegistryKey startupapp = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
startupapp.SetValue("App", "\"" + Assembly.GetExecutingAssembly().Location + "\"" +" -start");
Run Code Online (Sandbox Code Playgroud)
但问题是只有在我以管理员身份运行我的应用程序时才会添加注册表.有什么方法我可以避免这个事情,以便我的应用程序可以添加/删除启动应用程序的注册表项?
这是因为HKLM需要管理员权限才能写入.HKCU不要求这样做.
RegistryKey startupapp = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
startupapp.SetValue("App", "\"" + Assembly.GetExecutingAssembly().Location + "\"" +" -start");
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1155 次 |
| 最近记录: |