日期:2014-05-17 浏览次数:20730 次
/// <summary>
/// 注册表操作,将程序添加到启动项
/// </summary>
try
{
Microsoft.Win32.RegistryKey Reg;
string ShortFileName = Application.ProductName;
Reg = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Run", true);
if (Reg == null)
{
Reg = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Run");
}
Reg.SetValue(ShortFileName, Application.ExecutablePath);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
//////////取消启动
string ShortFileName = Application.ProductName; //获得应用程序名
try
{
Microsoft.Win32.RegistryKey Reg;
Reg = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Run", true);
if (Reg == null)
{
Reg = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("Software\\M