C# 设置/取消程序 开机自启动

(修改注册表)

【设置开机自启动】

using Microsoft.Win32;//添加命名空间

public static bool SetAutoRun(string keyName,string filePath)

        {

            try

            {

                RegistryKey runKey=Registry.LocalMachine.OpenSubKey(@"\SOFTWARE\Microsoft\Windows\CurrentVersion\Run",true);

                runKey.SetValue(keyName,filePath);

                runKey.Close();

            }

            catch

            {

                return false;

            }

            return true;

        }

【取消开机自启动】

using Microsoft.Win32;//添加命名空间

public static bool DeleteAutoRun(string keyName,string filePath)

        {

            try

            {

                RegistryKey runKey=Registry.LocalMachine.OpenSubKey(@"\SOFTWARE\Microsoft\Windows\CurrentVersion\Run",true);

                runKey.DeleteValue(keyName,filePath);

                runKey.Close();

            }

            catch

            {

                return false;

            }

            return true;

        }另外一种方式,将对应的应用,或者应用的快捷方式放置在开始文件列表中。
时间: 2024-07-30 23:12:49

C# 设置/取消程序 开机自启动的相关文章

设置让程序开机自启动的方法

以下方法均可以让程序开机自启动. 1.    在/etc/rc.d/rc.sysinit 末尾添加命令或要执行的程序脚本该脚本run once at boot time.所以对所有启动级别都有效 2.    在/etc/rc.d/rc.local中添加命令或要执行的程序脚本这个脚本将被执行在所有其他的init脚本执行完成后,默认对2345启动级别有效. 3.    在对应启动级别的/etc/rc.d/rcX.d 做连接文件连接的格式如:ln  -s  /etc/rc.d/init.d/xx  /

C#设置某程序开机自启动[修改注册表方式]

1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 using System.Threading.Tasks; 6 using Microsoft.Win32; 7 using org.nipc.securityManager.client.UpdateModule; 8 9 namespace SettingAutoRun 10 { 11 class Pr

cenOS设置程序开机自启动的方法

cenOS设置程序开机自启动的方法主要有两种 1.把启动程序的命令添加到/etc/rc.d/rc.local 文件夹中. eg1.设置开机启动mysql vim /etc/rc.d/rc.local #!/bin/sh # # This script will be executed *after* all the other init scripts. # You can put your own initialization stuff in here if you don't # want

C#如何设置程序开机自启动

如果想要将一个exe程序设置为开机自启动,其实就是在HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Run注册表项中添加一个注册表变量,这个变量的值是程序的所在路径. 具体操作步骤是: 1.使用RegistryKey类的CreateSubKey方法打开HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Ru

Windows下通过写注册表的方式实现程序开机自启动

程序可以读取同目录下的config.ini文件中的配置来实现开机自启动. config.ini文件地格式实例如下: [Main] KeyName = test ProcessPath = D:\bin\test.exe 其中KeyName字段为写入注册表的表项名称(可以设置为程序名) ProcessPath为程序的完整路径 程序的完整源代码如下. regedit函数实现注册表写入,autopen实现开机自启动. 编译后的程序在此下载:程序下载 #include <stdio.h> #inclu

android 程序开机自启动

今天遇到程序开机自启动,然后查了一下,很简单,就记录一下. 开机自启动,一般我们是开启启动一个广播,然后在广播里启动Activity或者别的服务. 我们要做的很简单,就是在AndroidManifest.xml  里面的广播中添加一行代码 <receiver android:name="广播名称"> <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED

mac设置shell脚本开机自启动

最近需要做分布式架构的网站,目前一直在调试阶段,每次开机的时候都要启动一大堆工具,比如zookeeper.activemq.redis.nginx等等,不厌其烦. 在网上搜了下mac如何设置shell脚本开机自启动,记录一下,方便自己也方便大家. 1.首先写一个sh脚本,比如: 1 cd ~/Documents 2 mkdir haha 代码很简单,进入Documents文件夹,建立haha目录,保存为run.sh 2.修改run.sh权限 sudo chmod 777 run.sh 3.右键点

linux 让一个程序开机自启动并把一个程序加为服务

本文以tomcat7为例 首先找到tomcat启动的目录,我的为 cd /usr/local/tomcat7/bin/ 这个目录 启动脚本是startup.sh 然后在/etc/rc.d/rc.local 这个文件中将tomcat的启动脚本添加进来即可. 重启操作系统,发现tomcat7可以开机自启动了. 将tomcat添加为服务 将 /usr/local/tomcat7/bin/catalina.sh 这个文件拷贝到 /etc/rc.d/init.d 这个目录并重命名为tomcat 使用命令

程序开机自启动

关于让程序在手机开机的时候自启动,给一个小的Demo 1. [代码]主活动界面 package com.android.antking.startloading; import android.app.Activity; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.os.Bundle; public c