如何在Windows启动时启动exe

nig*_*her 25 c# windows startup

可能重复:
如何将exe文件放在Windows启动中

假设我已经在C#中构建了一个应用程序,一旦我安装它,我希望它在Windows启动时在后台运行,或者你可以说用户登录到他的Windows帐户.有什么方法可以做到吗?写一个Windows服务除外?

应用程序基本上显示某个事件被触发时的消息谢谢

Bad*_*ari 56

添加到Windows启动文件夹的快捷方式:

Environment.GetFolderPath(Environment.SpecialFolder.Startup)
Run Code Online (Sandbox Code Playgroud)

或添加到注册表,如下所示:

RegistryKey add = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
add.SetValue("Your App Name", "\"" + Application.ExecutablePath.ToString() + "\"");
Run Code Online (Sandbox Code Playgroud)

如果希望将CurrentUser与每个用户一起运行,可以将其更改为LocalMachine.感谢Aidiakapi.

  • 请注意,您可以将Registry.CurrentUser更改为Registry.LocalMachine,以便为每个用户启用它.+1代码示例.另一个注意事项:你可以使用:`@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run"`而不是:``SOFTWARE \\ Microsoft \\ Windows \\ CurrentVersion \\ Run"`来取消`\`的转义字符. (17认同)

Jon*_*han 13

这可以使用Windows注册表完成.我建议你检查这个注册表项.

HKLM\Software\Microsoft\Windows\CurrentVersion\Run
HKLM\Software\Microsoft\Windows\CurrentVersion\RunOnce
HKLM\Software\Microsoft\Windows\CurrentVersion\RunServices
HKLM\Software\Microsoft\Windows\CurrentVersion\RunServicesOnce
HKCU\Software\Microsoft\Windows\CurrentVersion\Run
HKCU\Software\Microsoft\Windows\CurrentVersion\RunOnce
HKCU\Software\Microsoft\Windows\CurrentVersion\RunOnceEx 
Run Code Online (Sandbox Code Playgroud)