zoukankan      html  css  js  c++  java
  • C#编写的windows程序随系统启动的问题

    C#写了一个windows的程序,想让它随系统启动运行

    --------------

    把可执行文件的快捷方式复制到启动文件夹里面,这样不安全,安全的方法是把系统做成WinService的方式,以系统服务的方式安全好多

    --------------

    设置某程序随系统启动自动运行,取消自动运行。 使用到using Microsoft.Win32;名称空间。

    public void SetAutoRun(string fileName, bool isAutoRun)  
            {  
                    RegistryKey reg = null;  
                    try 
                    {  
                        if (!System.IO.File.Exists(fileName))  
                            throw new Exception("该文件不存在!");  
                        String name = fileName.Substring(fileName.LastIndexOf(@"\") + 1);  
                        reg = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run", true);  
                        if (reg == null)  
                            reg = Registry.LocalMachine.CreateSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run");  
                        if (isAutoRun)  
                            reg.SetValue(name, fileName);  
                        else 
                            reg.SetValue(name, false);
                        MessageBox.Show("设定成功!","提示");
                    }  
                    catch 
                    {  
                        //throw new Exception(ex.ToString());  
                    }  
                    finally 
                    {  
                        if (reg != null)  
                            reg.Close();  
                    }  
             }

    使用此方法可设置某程序自动运行和取消自动运行。fileName:设置(取消)自动运行程序的完整地址,isAutoRun:是否设置自动运行和取消自动运行。true,自动运行。false,取消自动运行。

    原理:操作注册表。

    --------------

    http://www.ziyouxue.net/2009/0804/5970.html

    http://topic.csdn.net/t/20050225/16/3806744.html

  • 相关阅读:
    wsl手动启动特定的子系统
    winserver安装wsl
    wsl子系统下载地址-补充centos7地址
    wsl (1)-含wsl子系统各启动命令
    win10系统版本说明
    zenith 以及海康 rtsp流
    shinobi (4)
    ffmpeg
    CF993A Two Squares 几何 第二道 暴力或判断条件(*)
    CF994B Knights of a Polygonal Table 第一道 贪心 set/multiset的用法
  • 原文地址:https://www.cnblogs.com/emanlee/p/1557380.html
Copyright © 2011-2022 走看看