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里显示路径
}
}
}