Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Query regarding the code in MatixCoder's "Autorun Applications" CodeProject article?

Query regarding the code in MatixCoder's "Autorun Applications" CodeProject article?

Scheduled Pinned Locked Moved Visual Basic
databasewindows-adminquestion
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Paul Hasler
    wrote on last edited by
    #1

    In the application I'm developing, I'd like to give the user the option to automatically start the application when windows starts. From my searches it looks like setting a registry key is one of the best ways to do it. I haven't ever played with the Registry in my programs before (I've only ever manually edited the registry), so I want to make sure I get it right. I came across MatrixCoder's article "Autorun Applications" which is quite clear and straight forward. He uses the following sub and passes it System.Reflection.Assembly.GetEntryAssembly.Location for path in order to set the registry key.

    Private Sub AddCurrentKey(ByVal name As String, ByVal path As String)
    Dim key As RegistryKey = Registry.CurrentUser.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Run", True)
    key.SetValue(name, path)
    End Sub

    If the key already exists, will this just overwrite it, or will it add another key each time AddCurrentKey() is called? If it would keep on adding further keys, how would the code best be modified to check if the key already exists? Regards Paul Hasler

    modified on Tuesday, January 19, 2010 5:03 AM

    L D 2 Replies Last reply
    0
    • P Paul Hasler

      In the application I'm developing, I'd like to give the user the option to automatically start the application when windows starts. From my searches it looks like setting a registry key is one of the best ways to do it. I haven't ever played with the Registry in my programs before (I've only ever manually edited the registry), so I want to make sure I get it right. I came across MatrixCoder's article "Autorun Applications" which is quite clear and straight forward. He uses the following sub and passes it System.Reflection.Assembly.GetEntryAssembly.Location for path in order to set the registry key.

      Private Sub AddCurrentKey(ByVal name As String, ByVal path As String)
      Dim key As RegistryKey = Registry.CurrentUser.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Run", True)
      key.SetValue(name, path)
      End Sub

      If the key already exists, will this just overwrite it, or will it add another key each time AddCurrentKey() is called? If it would keep on adding further keys, how would the code best be modified to check if the key already exists? Regards Paul Hasler

      modified on Tuesday, January 19, 2010 5:03 AM

      L Offline
      L Offline
      loyal ginger
      wrote on last edited by
      #2

      Adding that key will not make your program automatically start when Windows starts. It will make your application start when a user logs on to Windows. When the user logs off the system, the program will be terminated if it is still running. To make your application start when Windows starts, you need to make your application a "Windows Service". If you search for "Windows Service" you will get plenty of information on how to make it. Good luck and happy programming!

      1 Reply Last reply
      0
      • P Paul Hasler

        In the application I'm developing, I'd like to give the user the option to automatically start the application when windows starts. From my searches it looks like setting a registry key is one of the best ways to do it. I haven't ever played with the Registry in my programs before (I've only ever manually edited the registry), so I want to make sure I get it right. I came across MatrixCoder's article "Autorun Applications" which is quite clear and straight forward. He uses the following sub and passes it System.Reflection.Assembly.GetEntryAssembly.Location for path in order to set the registry key.

        Private Sub AddCurrentKey(ByVal name As String, ByVal path As String)
        Dim key As RegistryKey = Registry.CurrentUser.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Run", True)
        key.SetValue(name, path)
        End Sub

        If the key already exists, will this just overwrite it, or will it add another key each time AddCurrentKey() is called? If it would keep on adding further keys, how would the code best be modified to check if the key already exists? Regards Paul Hasler

        modified on Tuesday, January 19, 2010 5:03 AM

        D Offline
        D Offline
        Dave Kreskowiak
        wrote on last edited by
        #3

        This doesn't make the application start when Windows starts. This makes it start whenever the user logs in on the machine. If the name is the same as an existing value, then that value will get overwritten. it will NOT create another copy of the same name/value pair.

        A guide to posting questions on CodeProject[^]
        Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
             2006, 2007, 2008
        But no longer in 2009...

        P 1 Reply Last reply
        0
        • D Dave Kreskowiak

          This doesn't make the application start when Windows starts. This makes it start whenever the user logs in on the machine. If the name is the same as an existing value, then that value will get overwritten. it will NOT create another copy of the same name/value pair.

          A guide to posting questions on CodeProject[^]
          Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
               2006, 2007, 2008
          But no longer in 2009...

          P Offline
          P Offline
          Paul Hasler
          wrote on last edited by
          #4

          Thank you once again Dave. I used the wrong terminology. I do actually want the application to start when the user logs on. You see so many programs today with preference options such as for example "Start Skype when windows starts", that I fell into the trap of using the same sloppy terminology. With your explanation of how this will behave, I can finish off my app. Cheers again Paul

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups