C# 写入注册表启动项

C# 写入注册表启动项

private void RegisterSelfKey()
{
    try
    {
        string strName = Application.ExecutablePath;
        if (!File.Exists(strName))
            return;
        string strnewName = strName.Substring(strName.LastIndexOf("\\") + 1);
        RegistryKey RKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
        if (RKey == null)
            RKey = Registry.LocalMachine.CreateSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run");
        RKey.SetValue(strnewName, strName);
    }
    catch
    {
        //TODO: 写入注册表失败
    }
}

你可能感兴趣的:(C#)