By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,708 Members | 2,095 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,708 IT Pros & Developers. It's quick & easy.

how to make my visual basic 2010 application to autorun when windows starts

P: 3
i was created an application in visual basic 2010 .but need to make my application to automatically run at windows start up.i know in vb6.0 but i dont know in vb2010 i got an idea to copy the application shortcut icon to windows start up folder may work but i dont know how to do that using coding this is my idea .if this works tell me the code if not tell me in u r way how to do that
Jul 29 '12 #1

✓ answered by PsychoCoder

It's a lot simpler than you know. The vale for getting your app to run on Windows load (Windows has to be loaded) in order for this to happen. If Windows aint loaded yet what happened?

Here's some sampler that shows how to get the right key and set it's value (I added an option to remove the value if you choose:

Expand|Select|Wrap|Line Numbers
  1. private void RunOnWindowsStartup(bool @checked)
  2. {
  3.     var key = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
  4.  
  5.     if (@checked)
  6.     {
  7.         if (key != null) 
  8.             key.SetValue("ApplicationName", Application.ExecutablePath);
  9.     }
  10.     else if (key != null) 
  11.         key.DeleteValue("ApplicationName");
  12. }
Hope that helps :)

Share this Question
Share on Google+
1 Reply


PsychoCoder
Expert Mod 100+
P: 465
It's a lot simpler than you know. The vale for getting your app to run on Windows load (Windows has to be loaded) in order for this to happen. If Windows aint loaded yet what happened?

Here's some sampler that shows how to get the right key and set it's value (I added an option to remove the value if you choose:

Expand|Select|Wrap|Line Numbers
  1. private void RunOnWindowsStartup(bool @checked)
  2. {
  3.     var key = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
  4.  
  5.     if (@checked)
  6.     {
  7.         if (key != null) 
  8.             key.SetValue("ApplicationName", Application.ExecutablePath);
  9.     }
  10.     else if (key != null) 
  11.         key.DeleteValue("ApplicationName");
  12. }
Hope that helps :)
Jul 30 '12 #2

Post your reply

Sign in to post your reply or Sign up for a free account.