我希望我的应用程序(WPF Window
)在Windows启动时启动。我尝试了不同的解决方案,但似乎没有人工作。我必须在我的代码中写入这些内容?Windows启动时启动窗口
7
A
回答
13
当你说你必须将注册表项添加到注册表中时,你是正确的。如果你想开始为当前用户应用
HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Run
:
添加一个关键。
或者:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run
如果要启动它为所有用户。
例如,从当前用户的应用程序:如果你想自动启动在Windows启动时所有的用户应用
var path = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Run";
RegistryKey key = Registry.CurrentUser.OpenSubKey(path, true);
key.SetValue("MyApplication", Application.ExecutablePath.ToString());
只需更换与
RegistryKey key = Registry.LocalMachine.OpenSubKey(path, true);
行第二行。
如果您不想再自动启动应用程序,只需删除注册表值。
这样:
var path = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Run";
RegistryKey key = Registry.CurrentUser.OpenSubKey(path, true);
key.DeleteValue("MyApplication", false);
此示例代码是为WinForms应用程序进行测试。如果您需要确定WPF应用程序的可执行文件的路径,请尝试以下操作。
string path = System.Reflection.Assembly.GetExecutingAssembly().Location;
只是路径到您的可执行文件替换 “Application.ExecutablePath.ToString()”。
相关问题
- 1. 启动窗口 - WPF
- 2. monotouch启动窗口
- 3. Windows Phone启动画面弹出窗口
- 4. 自动启动服务时,windows启动
- 5. 如何从运行时启动的.dll内启动Windows窗体
- 6. 如何在窗口shell启动时启动FileSystemWatcher
- 7. 在Windows机器启动时启动STAF
- 8. Windows 7启动/启动的时间
- 9. 在Windows 7启动时启动tomcat?
- 10. Windows服务启动时启动
- 11. 在Windows 7启动时启动程序(自动启动)
- 12. wpf窗口启动图像
- 13. 窗口启动工具
- 14. 更改启动窗口
- 15. 服务块窗口启动
- 16. 动画窗口开启(二)
- 17. Spark未启动主窗口
- 18. SFML不会启动窗口
- 19. 启动画面+主窗口
- 20. 在Windows启动时
- 21. 启动时如何禁用窗口IE
- 22. 空气:启动时最大化窗口
- 23. 启动pm2启动脚本的Windows启动时出错
- 24. 在Windows启动时启动VirtualBox和虚拟机启动
- 25. 在Windows启动时启动应用程序启动
- 26. 在Windows 7启动时显示默认窗口布局
- 27. 安装C#窗口在Windows启动时的应用程序
- 28. 如何自动启动窗口服务
- 29. 启动时启动
- 30. C#Windows窗体GUI - 监视Windows启动
您尝试过哪些解决方案? – BoltClock
我试着写一个关键的注册表:HKCU \ Software \ Microsoft \ Windows \ CurrentVersion \ Run – Nick
你有没有任何日志记录?无论如何,你在注册表项中存储什么?该解决方案应该可行。 –