public static void SetAutoStart()
{
try
{
string strAssName = Application.StartupPath + @"\" + Application.ProductName + @".exe";
string strShortFileName = Application.ProductName;
RegistryKey sunwatt = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
if (sunwatt == null)
{
sunwatt = Registry.LocalMachine.CreateSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run");
}
{
try
{
string strAssName = Application.StartupPath + @"\" + Application.ProductName + @".exe";
string strShortFileName = Application.ProductName;
RegistryKey sunwatt = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
if (sunwatt == null)
{
sunwatt = Registry.LocalMachine.CreateSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run");
}
sunwatt.SetValue(strShortFileName, strAssName);
}
catch (Exception)
{
}
}
}
catch (Exception)
{
}
}
切记在运行VS2010的时候要一定要以管理员身份运行;