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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • murlikrishna
    New Member
    • Jul 2012
    • 3

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

    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
  • PsychoCoder
    Recognized Expert Contributor
    • Jul 2010
    • 465

    #2
    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:

    Code:
    private void RunOnWindowsStartup(bool @checked)
    {
        var key = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
    
        if (@checked)
        {
            if (key != null) 
                key.SetValue("ApplicationName", Application.ExecutablePath);
        }
        else if (key != null) 
            key.DeleteValue("ApplicationName");
    }
    Hope that helps :)

    Comment

    Working...