设置开机启动小程序

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.IO;

using System.Text;

using Microsoft.Win32;//导入win32命名空间

using System.Windows.Forms;

namespace WindowsFormsApplication1

{

    public partial class Form1 : Form

    {

        public Form1()

        {

            InitializeComponent();

        }

        private void Form1_Load(object sender, EventArgs e)

        {

            label2.Visible = false;

        }

       private void button2_Click(object sender, EventArgs e)

        {

            textBox1.Text = "";

        }

        private void button1_Click(object sender, EventArgs e)

        {

            OpenFileDialog open = new OpenFileDialog();

            open.Filter = "可执行文件(*.exe)|*.exe";//只显示.exe可执行应用程序

            if (open.ShowDialog() == DialogResult.OK)

            {

                string filename;//所选择程序的路径

                string savefilename;//所选择程序的名?

               savefilename  = open.SafeFileName ;

               label2.Text = savefilename;

               filename = open.FileName;

                textBox1.Text = filename ;

            };

        }

        private void button3_Click(object sender, EventArgs e)

        {

            string path = textBox1.Text.Trim();

            string exeName = path.Substring(path.LastIndexOf("//") + 1);

            if (!File.Exists(path))//检查该文件是否存在

            {

                MessageBox.Show("File not found, or malformed inputê?", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);

                textBox1.Text = "";

                textBox1.Focus();

                return;

            }

            MessageBox.Show("The machine's security software will be prompted to choose whether to start the boot process, choose to allow ...", "Tips", MessageBoxButtons.OK, MessageBoxIcon.Information);

            RegistryKey key = Registry.LocalMachine.OpenSubKey("SOFTWARE//Microsoft//Windows//CurrentVersion//Run", true);//打开注册表子项

            key.SetValue(label2.Text, textBox1.Text);//设置为开机启动

            MessageBox.Show("Selection procedures will be restarting the machine start ...");

        }

 

        private void button4_Click(object sender, EventArgs e)

        {

            System.Environment.Exit(-1);

        }

        private void textBox1_DragEnter(object sender, DragEventArgs e)

        {

            if (e.Data.GetDataPresent(DataFormats.FileDrop))

                e.Effect = DragDropEffects.Link;

            else e.Effect = DragDropEffects.None;

        }

        private void textBox1_DragDrop(object sender, DragEventArgs e)

        {

            textBox1.Text = ((System.Array)e.Data.GetData(DataFormats.FileDrop)).GetValue(0).ToString();

            //拖拽程序,textBox1里显示路径

        }

    }

}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值