http://topic.csdn.net/t/20050921/16/4284732.html这里有个Delphi的。
http://topic.csdn.net/t/20011030/15/347967.html这个需要安装程序有没有人能说下程序开机自启的原理,最好给个C++/C#代码。
或者给一些相关的API(名称,使用方法)
http://topic.csdn.net/t/20011030/15/347967.html这个需要安装程序有没有人能说下程序开机自启的原理,最好给个C++/C#代码。
或者给一些相关的API(名称,使用方法)
2 {
3 RegistryKey HKLM = Registry.LocalMachine;
4 RegistryKey Run = HKLM.CreateSubKey(@"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run\");
5 if (Started == true)
6 {
7 try
8 {
9 Run.SetValue(name, path);
10 HKLM.Close();
11 }
12 catch (Exception)
13 {
14 MessageBox.Show("注册表修改错误(开机自启未实现)");
15 }
16 }
17 else
18 {
19 try
20 {
21 if (Run.GetValue(name) != null)
22 {
23 Run.DeleteValue(name);
24 HKLM.Close();
25 }
26 else
27 return;
28 }
29 catch (Exception e)
30 {
31 ExceptionTransact.WriteErrLog(base.GetType().Name, e.Message);
32 //
33 }
34 }
35 }
这个地方比较详细
http://topic.csdn.net/u/20100118/09/c7d477c7-0984-4089-8dc0-c57219f5eb89.html?26411
using System.Collections.Generic;
using System.Text;
using Microsoft.Win32;namespace Notice
{
class RegistryManager
{
private static string keyName = "FinanceSysNotice";
private static string keyPath = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Run";
private static string keyValue = System.Reflection.Assembly.GetExecutingAssembly().Location + " /s"; /// <summary>
/// 添加启动项
/// </summary>
public static void AddKey()
{
RegistryKey k;
k = Registry.CurrentUser.CreateSubKey(keyPath);
k.SetValue(keyName, keyValue);
k.Close();
} /// <summary>
/// 检查键是否存在
/// </summary>
/// <returns></returns>
public static bool ExistKey()
{
string[] aimnames;
RegistryKey aimdir = Registry.CurrentUser.OpenSubKey(keyPath);
aimnames = aimdir.GetValueNames();
foreach (string aimKey in aimnames)
{
if (aimKey == keyName)
return true;
} return false;
} /// <summary>
/// 删除启动项
/// </summary>
public static void DeleteKey()
{
string[] aimnames;
RegistryKey aimdir = Registry.CurrentUser.OpenSubKey(keyPath, true);
aimnames = aimdir.GetValueNames();
foreach (string aimKey in aimnames)
{
if (aimKey == keyName)
{
aimdir.DeleteValue(keyName);
aimdir.Close();
break;
}
}
} /// <summary>
/// 检查启动项是否正常
/// </summary>
/// <param name="addReg">如果没有,是否添加?</param>
public static void CheckAutoRun(bool addReg)
{
try
{
//检查是否已有启动项
if (ExistKey())
{
//重新写入//增加新项
AddKey();
}
else
{
if (addReg)
{
//增加新项
AddKey();
}
}
}
catch (Exception ex)
{
throw new Exception("检查启动项时出现错误!\n" + ex.Message);
}
}
}
}
其实我觉得这个是最简单的答案看到大家都改了注册表么,又是一个学习点啊