本文实例讲述了C#实现程序开机启动的方法。分享给大家供大家参考,具体如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
//此方法把启动项加载到注册表中
//获得应用程序路径
string strAssName = Application.StartupPath + @"\" + Application.ProductName + @".exe" ;
//获得应用程序名
string ShortFileName = Application.ProductName;
RegistryKey rgkRun = Registry.LocalMachine.OpenSubKey( "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run" , true );
if (rgkRun == null )
{
rgkRun = Registry.LocalMachine.CreateSubKey( "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run" );
}
rgkRun.SetValue(ShortFileName, strAssName);
//此删除注册表中启动项
//获得应用程序名
string ShortFileName = Application.ProductName;
RegistryKey rgkRun = Registry.LocalMachine.OpenSubKey( "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run" , true );
if (rgkRun == null )
{
rgkRun = Registry.LocalMachine.CreateSubKey( "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run" );
}
rgkRun.DeleteValue(ShortFileName, false );
|
希望本文所述对大家C#程序设计有所帮助。