使用c#将应用程序添加到注册表以在启动时运行 [英] Adding application to registry for run at startup using c#

查看:88
本文介绍了使用c#将应用程序添加到注册表以在启动时运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已添加此代码以便在启动时运行



  public   static   void  AddApplicationToStartup()
{
using (RegistryKey key = Registry.CurrentUser.OpenSubKey( SOFTWARE \\ Microsoft \\ Windows \\ CurrentVersion \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ ( 我的程序 < span class =code-string> \ + Application.ExecutablePath + \ );
}
}





我已经在Main函数的第一行调用了这个函数。问题是每次都会运行。但是我们如何检查这个应用程序是否已经添加到注册表中?

解决方案

如果你可以写入注册表的某些部分,很明显你可以阅读它也。仔细查看您已经使用的注册表课程。



-SA

I have added this code for run at start up

public static void AddApplicationToStartup()
{
    using (RegistryKey key = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true))
    {
        key.SetValue("My Program", "\"" + Application.ExecutablePath + "\"");
    }
}



and i have called this function at the very first line of Main function. the problem is this will run every time. but how can we check that this application is already added to registery??

解决方案

If you can write to some part of the registry, it's quite apparent that you can read it, too. Look more thoroughly at the Registry class you are already using.

—SA


这篇关于使用c#将应用程序添加到注册表以在启动时运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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