一般我們在開發桌面應用程式也就是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
轉載請註明出處,並且附上本篇文章網址 !  感謝。

20 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.

發表迴響

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

Post Navigation