• 开机运行


    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();                 }             }

            }     } }

  • 相关阅读:
    win7跨网段加域提示"找不到网络路径",解决后又提示"将该计算机的主域DNS更改为“”失败,名称仍然为xx.xx, 错误为“指定的服务器无法运行请求的操作”!
    XP原版系统激活
    使用SQLyog远程连接mysql,错误1130 解决方法
    激活Windows Server 2008 R2 Enterprise 方法
    Non-UTF-8 code starting with 'xff'解决,记录
    Linux 中,基础命令 command not found...问题
    winxp_sp3未激活的登录问题
    linux安装tomcat
    Notepad++ 配置python
    python idle 清屏问题的解决
  • 原文地址:https://www.cnblogs.com/pnljs/p/2725475.html
Copyright © 2020-2023  润新知