Autorun.cs 1.1 KB

123456789101112131415161718192021222324252627282930313233
  1. using System;
  2. using System.IO;
  3. namespace MediaBrowser.ServerApplication.Native
  4. {
  5. /// <summary>
  6. /// Class Autorun
  7. /// </summary>
  8. public static class Autorun
  9. {
  10. /// <summary>
  11. /// Configures the specified autorun.
  12. /// </summary>
  13. /// <param name="autorun">if set to <c>true</c> [autorun].</param>
  14. public static void Configure(bool autorun)
  15. {
  16. var shortcutPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.StartMenu), "Media Browser 3", "Media Browser Server.lnk");
  17. var startupPath = Environment.GetFolderPath(Environment.SpecialFolder.Startup);
  18. if (autorun)
  19. {
  20. //Copy our shortut into the startup folder for this user
  21. File.Copy(shortcutPath, Path.Combine(startupPath, Path.GetFileName(shortcutPath) ?? "MBstartup.lnk"), true);
  22. }
  23. else
  24. {
  25. //Remove our shortcut from the startup folder for this user
  26. File.Delete(Path.Combine(startupPath, Path.GetFileName(shortcutPath) ?? "MBstartup.lnk"));
  27. }
  28. }
  29. }
  30. }