C#实现将应用程序设置为开机启动的方法
本文实例讲述了C#实现将应用程序设置为开机启动的方法。分享给大家供大家参考。具体如下:
privatevoidWriteRegistry()
{
stringstrName=Application.ExecutablePath;
if(File.Exists(strName))
{
stringstrNewName=Path.GetFileName(strName);
RegistryKeyreg=Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run",true);
if(reg==null)
{
reg=Registry.LocalMachine.CreateSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run");
}
else
{
if(reg.GetValue(strNewName)==null)
{
reg.SetValue(strNewName,strName);
}
}
}
}
希望本文所述对大家的C#程序设计有所帮助。