启动时运行程序 [英] Running a program at startup

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

问题描述

如何在启动时运行用C#编写的程序?

How do I run a program written with C# at startup?

推荐答案

最基本的选择是编写Windows Service.与常规应用程序相比,它具有重要的优势,但更难于开发和调试.用户注销并登录后,该服务将继续运行.

对于所有其他方式,我有一个更全面的方法,我发现它非常可靠.您可以在名为AutoRuns:
的SysInternals应用程序之后找到所有不同的方法来注册应用程序以一次或定期进行加载.
1)转到SysInternals网站: http://technet.microsoft.com/en-us/sysinternals [ ^ ].
2)下载SysInternals套件: http://download.sysinternals.com/Files/SysinternalsSuite.zip [ ^ ];您还可以下载单独的应用程序,但是还有更多有用的信息,请阅读实用程序索引: http://technet.microsoft. com/en-us/sysinternals/bb545027 [ ^ ].
3)解压并运行AutoRuns,阅读帮助并查看树的顶级项目:它们显示何时可以安装应用程序.
4)激活上下文菜单,然后选择跳转到";它将在所选项目上打开Regedit.
5)编写安装应用程序,它将安装程序的路径和参数写入注册表中的正确位置.

祝你好运,
—SA
Most fundamental option is writing a Windows Service is a serious option. It gives important benefits over regular applications, but also more difficult to develop and debug. The service keeps running when users log out and log in.

For all other ways, I have a more comprehensive method which I find very robust. You can find all different ways to register application for loading once or on regular basis following SysInternals application called AutoRuns:

1) Go to SysInternals site: http://technet.microsoft.com/en-us/sysinternals[^].
2) Download SysInternals Suit: http://download.sysinternals.com/Files/SysinternalsSuite.zip[^]; you can also download separate applications, but there are more useful things, read utilities Index: http://technet.microsoft.com/en-us/sysinternals/bb545027[^].
3) Unpack and run AutoRuns, read it help and look at the top-level items of the tree: they show when you can install your applications.
4) Activate context menu and select "Jump To"; it will open Regedit on a selected item.
5) Write installation application which writes the path to your application and parameters in a right place in the Registry.

Good luck,
—SA


您需要在启动时使用注册表来运行程序.您可以使用System.Win32名称空间中的RegistryKey 类.以下代码显示了如何执行此操作:

You need to use the Registry for running a program at startup. You can use the RegistryKey class that''s in the System.Win32 namespace. The following code shows how to do this:

RegistryKey rk = Registry.CurrentUser;
RegistryKey StartupPath;
StartupPath = rk.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run", true);
if (StartupPath.GetValue("ProjectName") == null)
{
    StartupPath.SetValue("ProjectName", Application.ExecutablePath, RegistryValueKind.ExpandString);
}



注意:RegistryKeySystem.Win32名称空间中,因此不要忘记导入它.



Note: RegistryKey is in the System.Win32 namespace, hence don''t forget to import it.


使用给定的链接在启动时运行程序

链接 [
use given Link to Run Program at Startup

Link[^]


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

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