C#应用程序自动启动 [英] C# application auto start

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

问题描述

你好,

我有一个具有表单和复选框的应用程序,我会将复选框状态保存在另一个文件中,以便我知道是否选中了....问题是这样的..我想,当复选框被选中的应用程序自动启动时启动Windows,反之亦然搜索结果我怎么也许可以通过添加注册表项槽程序处理这个?点击
Thx

Hello,

I have an application which has a form and a check box in it, i will save the check box state in another file so that i know whether it is checked or not... the problem is this .. i want that when the check box is checked the application auto starts when windows starts and vice versa

how can i deal with this maybe by adding a registry key trough the program?

Thx

推荐答案

我写了一个做到这一点的类:

I wrote a class that does that:

///< summary>
///启用或禁用应用程序的自动启动(使用OS).
///< ;/summary>
公共静态类AutoStarter
{
 私有常量字符串RUN_LOCATION = @"Software \ Microsoft \ Windows \ CurrentVersion \ Run";
 私有常量字符串VALUE_NAME =辣椒剪贴板";

///< summary>
 ///设置程序集的自动启动值. ;/summary>
 公共静态无效值SetAutoStart()
  {
  RegistryKey键= Registry.CurrentUser.CreateSubKey(RUN_LOCATION);
  key.SetValue (VALUE_NAME,Assembly.GetExecutingAssembly().位置);
 }

///< summary>
 ///返回是否启用了自动启动. /summary>
 公共静态布尔值IsAutoStartEnabled
  {
   get
 < RegistryKey键= Registry.CurrentUser. OpenSubKey(RUN_LOCATION);
   if(key == null)
    return false;

   字符串值=(string)key.GetValue(VALUE_NAME);
    if(value == null )
   返回false;
    return(值== Assembly.GetExecutingAssembly().Location);
 }
  ;}

///< summary>
 ///取消设置程序集的自动启动值. ;/summary>
 公共静态无效值UnSetAutoStart()
  {
  RegistryKey键= Registry.CurrentUser.CreateSubKey(RUN_LOCATION);
   key.DeleteValue (VALUE_NAME);
 }
}

您需要用应用程序名称替换VALUE_NAME.

You need to replace the VALUE_NAME with the name of your application.


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

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