在Windows启动时运行C#应用程序? [英] Run C# application at Windows startup?

查看:134
本文介绍了在Windows启动时运行C#应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

整天都在尝试在项目中实现启动功能.

It's all the day that I'm trying to implement a startup feature into my project.

我使用了注册表项:

//Computer\HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Run (Administrator Rights)

我使用了注册表项:

//Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run (Administrator Rights) 

代码可以正常工作,但是当我重新启动计算机时,什么也没发生.

The code work but when I restart the computer nothing happens.

这是我使用的代码.

RegistryKey registryKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
registryKey.SetValue("ApplicationService", Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "MyService.exe"));

我还使用了与快捷方式链接到.exe位置(在%appdata%内部)的Startup文件夹. 不幸的是,它没有用.

I also used Startup folder linked with a shortcut to my .exe location(inside %appdata%). Unfortunately, it didn't work.

我的操作系统是:Windows 10-PRO 1083. 我的项目是用C#开发的.

My operative system is: Windows 10 - PRO 1083. My project has been developed with C#.

您还知道其他吗?

我需要您弄清楚这个问题! 预先感谢您的回答

I need you to figure out that issue ! Thanks in advance for your answers

推荐答案

一种不错的简便方法是计划任务. Windows中有一个向导(在开始菜单中搜索:Task Scheduler),可以指导您完成整个过程.

One nice easy way to do this is a scheduled task. There's a wizard in Windows (search in the start menu: Task Scheduler) that should guide you through the process.

选择创建任务",然后可以将任务触发器设置为计算机启动.完成后,只需选择可执行文件即可,然后开始运行.

You select Create Task and can set the task trigger to be computer start-up. Once that's done, it should just be a matter of selecting your executable and from then it should run.

如果这不起作用,请尝试从.bat文件执行程序并在启动时运行它-可能有点小问题,但这可以缓解我以前在启动程序时遇到的问题.

If that doesn't work, try executing the program from a .bat file and running that at startup - it might be a little niche, but that's alleviated problems I've had before with programs on startup.

这篇关于在Windows启动时运行C#应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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