日期:2014-05-18  浏览次数:20766 次

winform问题
用winform做一个程序,怎么让他开机自动自启动?而且杀毒软件不会检测到?

------解决方案--------------------
将程序路径写到注册表 LocalMachine\software\microsoft\windows\currentversion\run 里面。
------解决方案--------------------
通过在Microsft.Win32命名空间的Registry可以在注册表中设置注册表项中的名称/值对的值。
在注册表的"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run"中
存储应用程序名和路径可以实现程序的自启动
------解决方案--------------------
C# code
public static bool SetAutoRun(string keyName,string filePath)
  {
  try
  {
  RegistryKey runKey=Registry.LocalMachine.OpenSubKey(@"\SOFTWARE\Microsoft\Windows\CurrentVersion\Run",true);
  runKey.SetValue(keyName,filePath);
  runKey.Close();
  }
  catch
  {
  return false;
  }
  return true;
  }