#region 设置开机运行 /// <summary> /// 设置开机运行 /// </summary> /// <param name="R_startPath">需要运行的程序.exe</param> /// <returns></returns> public static bool SetStartRun(string R_startPath) { if (!File.Exists(R_startPath)) return false; FileInfo fi = new FileInfo(R_startPath); string newName = fi.Name; 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(newName, R_startPath); Rkey.Close(); return true; } #endregion
说明:
1、需要给winform软件管理员权限
2、R_startPath为:winfrom软件exe文件的完整路径