开机自动运行的方法
using Microsoft.Win32;//Registry的引用空间.
private void FrmTiming_Load(object sender, EventArgs e)
{
AutoRun();
}
/// <summary>
/// windows启动时,自动运行
/// </summary>
private void AutoRun()
{
try
{
string path = Application.ExecutablePath;
if (!System.IO.File.Exists(path))
return;
string myName = path.Substring(path.LastIndexOf("""") + 1);
RegistryKey myReg = Registry.LocalMachine.OpenSubKey("SOFTWARE""Microsoft""Windows""CurrentVersion""Run", true);
if (myReg == null)
myReg = Registry.LocalMachine.CreateSubKey("SOFTWARE""Microsoft""Windows""CurrentVersion""Run");
myReg.SetValue(myName, path);
}
catch
{
Application.Exit();
}
}
浙公网安备 33010602011771号