一般我們在開發桌面應用程式也就是Windows Form時,有可能會製作需要常駐在系統的應用程式,並且不希望使用者還須都動開啟,這個時候我們就可以使應用程式在開機時自動運行。

本篇文章將引導您讓應用程式在開機時自動啟動。

 

本篇文章的訴求的功能非常明瞭,所以也沒有什麼好敘述的,

這是SUKI很久以前寫過的專案,突然最近有需要用到這個功能,剛好就翻出來使用了,

與國家未來的棟樑們做個分享!!

就直接看Code吧!

 

 try
 {
     //宣告登錄檔名稱
     string app_name = "myApp";
     //選告一個字串表示本身應用程式的位置後面加的是參數"-s"
     //若沒有附帶啟動參數的話可以不加
     string R_startPath = Application.ExecutablePath + " -S";
     //開啟登錄檔位置,這個位置是存放啟動應用程式的地方
     RegistryKey aimdir = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run", true);
     //若登錄檔已經存在則刪除
     if (aimdir.GetValue(app_name) != null)
     {
         //刪除
         aimdir.DeleteValue(app_name, false);
     }
     //寫入登錄檔值
     aimdir.SetValue(app_name, R_startPath);
     //關閉登錄檔
     aimdir.Close();
  
 }
 catch(Exception ex)
 {
     Console.WriteLine("登錄檔寫入失敗:"+ex.Message);
 }

 

如此一來我們就可以讓自己開發的應用程式在開機時自動啟動了!

 

References : C#開機自動執行程序

 

文章中的敘述如有觀念不正確錯誤的部分,歡迎告知指正 謝謝
http://www.sukitech.com/?p=922
轉載請註明出處,並且附上本篇文章網址 !  感謝。

65 Thoughts on “C# Windows Form 開發,讓應用程式開機時自動啟動。

  1. 訪客 on 2015-11-05 at 2:34 下午 said:

    謝謝分享!!!!

  2. Hey, thanks for the blog article.Thanks Again. Really Cool.

  3. Major thankies for the blog. Keep writing.

  4. Thanks so much for the post. Really Cool.

  5. I really liked your article.Really thank you! Cool.

  6. Great, thanks for sharing this post.Much thanks again.

  7. I think this is a real great blog article.Much thanks again. Cool.

  8. I really like and appreciate your post.Really looking forward to read more. Much obliged.

  9. Major thankies for the article post. Awesome.

  10. I am so grateful for your article.

  11. I think this is a real great blog.Really thank you! Much obliged.

  12. Very good article post. Much obliged.

  13. Very informative blog article.Really looking forward to read more. Really Cool.

  14. Thanks so much for the article post. Cool.

  15. Im obliged for the blog.Thanks Again. Awesome.

  16. I really liked your blog.Thanks Again. Will read on…

  17. Thanks-a-mundo for the article.Really looking forward to read more. Keep writing.

  18. Thanks-a-mundo for the blog article.Really looking forward to read more. Awesome.

  19. Really informative blog post.Really thank you! Awesome.

  20. Awesome blog article.Thanks Again. Really Cool.

  21. Say, you got a nice post.Really looking forward to read more. Fantastic.

  22. I really enjoy the article.Really looking forward to read more. Awesome.

  23. Thanks a lot for the article.Much thanks again. Fantastic.

  24. Very neat article.Really looking forward to read more. Fantastic.

  25. Major thankies for the blog article.Much thanks again. Cool.

  26. Very informative blog article.Really thank you! Really Great.

  27. Major thanks for the post.Really looking forward to read more. Great.

  28. I appreciate you sharing this blog.Much thanks again. Want more.

  29. I think this is a real great article.Much thanks again. Great.

  30. I think this is a real great blog.Thanks Again. Want more.

  31. Thank you for your article.Thanks Again. Cool.

  32. Major thanks for the blog article.Much thanks again. Really Great.

  33. I am so grateful for your blog article.Really looking forward to read more. Great.

  34. Muchos Gracias for your blog. Really Great.

  35. wow, awesome blog post.Much thanks again.

  36. I really like and appreciate your post. Will read on…

  37. Muchos Gracias for your blog.Really thank you! Keep writing.

  38. Awesome blog article.Much thanks again. Will read on…

  39. I value the article post. Fantastic.

  40. I am so grateful for your article post.Much thanks again. Great.

  41. I think this is a real great blog.

  42. Say, you got a nice blog article.Really thank you! Want more.

  43. I appreciate you sharing this article post.Thanks Again. Great.

  44. Looking forward to reading more. Great blog.

  45. Thank you ever so for you blog post.Really thank you! Really Great.

  46. Thanks-a-mundo for the article post. Great.

  47. wow, awesome blog article.Thanks Again. Really Cool.

  48. Major thanks for the blog.Really thank you! Really Cool.

  49. I appreciate you sharing this post.Much thanks again. Keep writing.

  50. Thank you ever so for you article post.Thanks Again. Keep writing.

  51. Appreciate you sharing, great blog.Much thanks again. Really Great.

  52. Thank you ever so for you article.Much thanks again. Awesome.

  53. I really enjoy the post.Thanks Again. Awesome.

  54. Very informative article.Thanks Again. Awesome.

  55. Im obliged for the article.Much thanks again. Much obliged.

  56. Really enjoyed this article. Want more.

  57. Very informative blog.Really thank you! Really Great.

  58. Looking forward to reading more. Great blog article.Much thanks again. Fantastic.

  59. Thank you ever so for you article.Much thanks again. Awesome.

  60. I value the article post.Really thank you! Cool.

發表迴響

你的電子郵件位址並不會被公開。

Post Navigation