c#将程序添加到windows启动(windows 7) [英] c# add program to windows startup (windows 7)

查看:39
本文介绍了c#将程序添加到windows启动(windows 7)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过将程序执行路径添加到注册表编辑器来将我的程序添加到 Windows 启动程序中.

I'm trying to add my program to the windows start up programs by adding the program execution path to the registry editor.

这是代码:

RegistryKey registryKey = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);  
registryKey.SetValue("progExe", Application.ExecutablePath);

奇怪的是,当我重新启动计算机时,程序在启动时没有运行...

Surprisingly, when i restart the computer, the program does not run in the startup...

我可以看到程序是 msconfig 窗口,勾选了它的复选框..但是当我去那个注册表路径时,我根本找不到我使用的密钥("progEXE")...我确保我在正确的注册表路径中搜索...

I can see the the program is the msconfig window ,with it's checkbox ticked.. but when i go that registry path,i can't find the key i used at all("progEXE")...i made sure i'm searching in the right registry path...

有没有人知道在这种情况下可能出现什么问题?

Does anyone has any idea what could be the problem in this case?

提前致谢.

推荐答案

题外话:在尝试设置值之前添加一个空检查,或者像这样写一个问号registryKey?.SetValue(..."

Off-topic: add a null check before trying to set the value, or write with a questionmark like so "registryKey?.SetValue(..."

这篇关于c#将程序添加到windows启动(windows 7)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆