开机启动代码

开机启动代码.txt其实全世界最幸福的童话,不过是一起度过柴米油盐的岁月。一个人愿意等待,另一个人才愿意出现。感情有时候只是一个人的事,和任何人无关。爱,或者不爱,只能自行了断。using System;
using System.Collections.Generic;
using https://www.360docs.net/doc/4d18442336.html,ponentModel;
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\Application1.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, https://www.360docs.net/doc/4d18442336.html,rmation);
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.Environme

nt.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());

}

}




}

相关文档
最新文档