如何创建一个控制台应用程序以在 Windows 以 C# 启动时自动运行?我怎么能以编程方式做到这一点。我试过这个whay...
RegistryKey rkApp =
Registry.LocalMachine.OpenSubKey
("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run ", true);
rkApp.SetValue("MyAPP", Assembly.GetExecutingAssembly().Location);
但在当前上下文中找不到 SetValue 方法。
使用 CurrentUser 而不是 LocalMachine:
RegistryKey rkApp = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
去掉 \Run 后的空格,并使用以下命令设置值:
rkApp.SetValue("MyApp", Application.ExecutablePath);
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句