zoukankan      html  css  js  c++  java
  • 开机运行

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using Microsoft.Win32;
    using System.IO;

    namespace SetStart
    {    
    public partial class Form1 : Form    
    {        
    public Form1()         {             InitializeComponent();         }

            private void btnAdd_Click(object sender, EventArgs e)         {             //获得文件的当前路径             string dir = Directory.GetCurrentDirectory();             //获取可执行文件的全部路径             string exeDir = dir + @"\SetStart.exe";

                string strName = Application.ExecutablePath;

                SetAutoRun(exeDir, true);         }         public static void SetAutoRun(string fileName, bool isAutoRun)         {             RegistryKey reg = null;             try             {                 if (!File.Exists(fileName))                 {                     throw new Exception("木有这个文件,搞什么搞");                 }                 string name = fileName.Substring(fileName.LastIndexOf(@"\") + 1);                 reg = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);//true 代表是开机运行。                 if (reg == null)                     reg = Registry.LocalMachine.CreateSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run");                 if (isAutoRun)                 {                     reg.SetValue(name, fileName);                     MessageBox.Show("开机可以黑屏了", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);                 }

                    else                     reg.SetValue(name, false);             }             catch (Exception ex)             {

                    throw new Exception(ex.ToString());             }             finally             {                 if (reg != null)                 {                     reg.Close();                 }             }

            }     } }

  • 相关阅读:
    单例模式-静态内部类方式
    单例模式-懒汉式(双重检验)
    单例模式-懒汉式
    sonarqube7.2版本web api简析
    sonarqube集成maven插件,上传扫描结果
    sonarQube快速入门7.2版本下载pmd插件,并设置只使用pmd规则
    gradle使用dokka插件出现Exception while loading package-list from ExternalDocumentationLinkImp
    让linux后解压的资源权限就是777(工作笔记)
    java并发 无锁cas的最简单理解
    java 必须要懂点的包 今日研究小结
  • 原文地址:https://www.cnblogs.com/pnljs/p/2725475.html
Copyright © 2011-2022 走看看