开机启动代码
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;
namespace ManagerAide
{
public partial class System : Form
{
public System()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
RunWhenStart(true, "ÖúÊÖ",
@"F:\µÚ?þÑ?ÆÚ\Winform\ÈÕ???ÜÀíÖúÊÖ\ManagerAide\ManagerAide\bin\Debug\ManagerAide.exe"); //µ?ÓÃ???Å ???ÌÐòÃûÒÔ??Â???
}
//ʵÏÖ?ª?ú×ÔÆô????ÄÜ??????Ö??ÓÊ?ÓÃÏÂÃæµÄ???Å?Í?ÉÒÔ
public void RunWhenStart(bool Started, string name, string path)
{
RegistryKey HKLM = Registry.LocalMachine; //×??á?í
RegistryKey Run =
HKLM.CreateSubKey(@"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run\");
try
{
Run.SetValue(name, path); //?æ?øÈ?
HKLM.Close();
MessageBox.Show("ÒÑ?É??ÉèÖÃ?ª?ú×ÔÆô??");
}
catch (System.Exception ex)
{
MessageBox.Show("×??á?íÐÞ?Ä?íÎó??Î?ʵÏÖ?ª?ú×ÔÆô??");
}
}
private void button2_Click(object sender, EventArgs e)
{
closeWhenStart();
}
//?Ø?Õ?ª?úÆô??
private void closeWhenStart()
{
// MessageBox.Show("Ã?ÓÐÑ?ÖÐ");
//?ñÈ??ÌÐòÖ?ÐÐÂ???..
// string starupPath =
@"F:\µÚ?þÑ?ÆÚ\Winform\Exercise01\Application1\bin\Debug\Applicatio
n1.exe";
//class Micosoft.Win32.RegistryKey. ?íÊ?Window×??á?íÖÐÏî???Úµã,?ËÀàÊÇ×??á?í×?.
RegistryKey loca = Registry.LocalMachine;
RegistryKey run =
loca.CreateSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run"
);
try
{
//SetValue:?æ??ÖµµÄÃû?Æ
run.DeleteValue("ÖúÊÖ");
MessageBox.Show("ÒÑÍ?Ö??ª?úÔËÐÐ!", "ÌáÊ?", MessageBoxButtons.OK, MessageBoxIcon.Information);
loca.Close();
}
catch (Exception ee)
{
MessageBox.Show(ee.Message.ToString(), "ÌáÊ?", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void button3_Click(object sender, EventArgs e)
{
int hm = System.Environment.TickCount;
double h = hm / 3600000.0;
double m = double.Parse("0." +
h.ToString("F6").Substring(h.ToString().IndexOf(".") + 1)) * 60;
double s = double.Parse("0." +
m.ToString("F6").Substring(m.ToString().IndexOf(".") + 1)) * 60;
string h1 = ((int)h).ToString();
string m1 = ((int)m).ToString();
string s1 = ((int)s).ToString();
if ((int)h < 10) h1 = "0" + h1;
if ((int)m < 10) m1 = "0" + m1;
if ((int)s < 10) s1 = "0" + s1;
string nowtime =
DateTime.Now.TimeOfDay.ToString().Substring(0, 8);
string span = h1 + ":" + m1 + ":" + s1;
TimeSpan spantime =
Convert.ToDateTime(nowtime).Subtract(Convert.ToDateTime(span));
MessageBox.Show("ÄúµÄ?ª?úÊ??äÊÇ?º " + spantime.ToString());
}
}
}