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. Using the registry for automatic startup

Using the registry for automatic startup

Scheduled Pinned Locked Moved Visual Basic
windows-adminlinuxdebuggingbeta-testinghelp
9 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.
  • R Offline
    R Offline
    RyJaBy
    wrote on last edited by
    #1

    Hi, I was wondering if anyone knew how to put your application into the msconfig startup folder using the registry. I tried using the following code but for some reason it isnt working for me. it will work when i debug, but when i publish the application it doesnt work.

    Private Sub addstart()

        registrykey = CreateObject("WScript.shell")
        registrykey.RegWrite("HKEY\_CURRENT\_USER\\SOFTWARE\\MICROSOFT\\WINDOWS\\CURRENTVERSION\\RUN\\" & App, filepath)
    
    
    End Sub
    Private Sub removeStart()
        On Error Resume Next
    
    
        registrykey = CreateObject("WScript.shell")
        registrykey.RegDelete("HKEY\_CURRENT\_USER\\SOFTWARE\\MICROSOFT\\WINDOWS\\CURRENTVERSION\\RUN\\PEM beta.exe")
    End Sub
    

    Is there a better way to do this? Thanks

    D L 2 Replies Last reply
    0
    • R RyJaBy

      Hi, I was wondering if anyone knew how to put your application into the msconfig startup folder using the registry. I tried using the following code but for some reason it isnt working for me. it will work when i debug, but when i publish the application it doesnt work.

      Private Sub addstart()

          registrykey = CreateObject("WScript.shell")
          registrykey.RegWrite("HKEY\_CURRENT\_USER\\SOFTWARE\\MICROSOFT\\WINDOWS\\CURRENTVERSION\\RUN\\" & App, filepath)
      
      
      End Sub
      Private Sub removeStart()
          On Error Resume Next
      
      
          registrykey = CreateObject("WScript.shell")
          registrykey.RegDelete("HKEY\_CURRENT\_USER\\SOFTWARE\\MICROSOFT\\WINDOWS\\CURRENTVERSION\\RUN\\PEM beta.exe")
      End Sub
      

      Is there a better way to do this? Thanks

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

      RyJaBy wrote:

      how to put your application into the msconfig startup folder

      And just what do you mean by "msconfig startup folder"?? What do you mean by "it doesn't work"? The Run key values are all command lines that execute only when a user logs in. The name/value pair you create in the Run key must have a unique name and its value must be a valid command line that would work just as if you copied it into the Start/Run box.

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

      R 1 Reply Last reply
      0
      • D Dave Kreskowiak

        RyJaBy wrote:

        how to put your application into the msconfig startup folder

        And just what do you mean by "msconfig startup folder"?? What do you mean by "it doesn't work"? The Run key values are all command lines that execute only when a user logs in. The name/value pair you create in the Run key must have a unique name and its value must be a valid command line that would work just as if you copied it into the Start/Run box.

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

        R Offline
        R Offline
        RyJaBy
        wrote on last edited by
        #3

        If you go to run and you type in msconfig you will get a window,"system configuration utility" that has a tab on it called startup. In the tab is all the applications that run when your computer starts up. When it was working, it would put the name of my application into this list on the startup tab, it does that when i am debugging. When i publish the application and install it on my computer, it doesnt write its name into that list when i tell it to.

        D 1 Reply Last reply
        0
        • R RyJaBy

          If you go to run and you type in msconfig you will get a window,"system configuration utility" that has a tab on it called startup. In the tab is all the applications that run when your computer starts up. When it was working, it would put the name of my application into this list on the startup tab, it does that when i am debugging. When i publish the application and install it on my computer, it doesnt write its name into that list when i tell it to.

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

          That tab is just a compilation of the various startup locations that track which application should launch when a user logs in. Those include the Run keys under HKEY_LOCAL_MACHINE and HKEY_CURRENT_USER as well as the shortcuts that appear in "Documents and Settings\All Users\Start Menu\Programs\Startup" and "Documents and Settings\\Start Menu\Programs\Startup". Your code won't work for a list of reasons. The first of which is that you have On Error Resume Next in there and it's eating your error messages. Your code should look like this:

          Set wshShell = WScript.CreateObject("WScript.shell")
          wshShell.RegWrite "HKCU\SOFTWARE\MICROSOFT\WINDOWS\CURRENTVERSION\RUN\" & App, filepath

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

          1 Reply Last reply
          0
          • R RyJaBy

            Hi, I was wondering if anyone knew how to put your application into the msconfig startup folder using the registry. I tried using the following code but for some reason it isnt working for me. it will work when i debug, but when i publish the application it doesnt work.

            Private Sub addstart()

                registrykey = CreateObject("WScript.shell")
                registrykey.RegWrite("HKEY\_CURRENT\_USER\\SOFTWARE\\MICROSOFT\\WINDOWS\\CURRENTVERSION\\RUN\\" & App, filepath)
            
            
            End Sub
            Private Sub removeStart()
                On Error Resume Next
            
            
                registrykey = CreateObject("WScript.shell")
                registrykey.RegDelete("HKEY\_CURRENT\_USER\\SOFTWARE\\MICROSOFT\\WINDOWS\\CURRENTVERSION\\RUN\\PEM beta.exe")
            End Sub
            

            Is there a better way to do this? Thanks

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            Remove the demon "On Error Resume Next" and you will be able to see what the problem is. Most probably, you have an access issue, the account under which the code runs must have permissions to modify the registry key.

            D 1 Reply Last reply
            0
            • L Lost User

              Remove the demon "On Error Resume Next" and you will be able to see what the problem is. Most probably, you have an access issue, the account under which the code runs must have permissions to modify the registry key.

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

              Yeah, there's a lot more wrong with his code than access permissions to the Run key... I think I found at least 5 errors in his two lines of code.

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

              R 1 Reply Last reply
              0
              • D Dave Kreskowiak

                Yeah, there's a lot more wrong with his code than access permissions to the Run key... I think I found at least 5 errors in his two lines of code.

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

                R Offline
                R Offline
                RyJaBy
                wrote on last edited by
                #7

                Is going through the registry even a good way to try to have your application run on startup? Or should I be trying to find a different way to do this. Maybe is there a way to, using code, create a shortcut in the startup folder? and would you be able to delete this shortcut using code, so the user would not have to do anything except check a box? I would like the user to be able to select an option that would cause the application to start automatically. Thanks

                D 1 Reply Last reply
                0
                • R RyJaBy

                  Is going through the registry even a good way to try to have your application run on startup? Or should I be trying to find a different way to do this. Maybe is there a way to, using code, create a shortcut in the startup folder? and would you be able to delete this shortcut using code, so the user would not have to do anything except check a box? I would like the user to be able to select an option that would cause the application to start automatically. Thanks

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

                  You're already doing it. You either put the shortcut in one of the four startup locations mention in my previous post, or you don't bother with it at all.

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

                  R 1 Reply Last reply
                  0
                  • D Dave Kreskowiak

                    You're already doing it. You either put the shortcut in one of the four startup locations mention in my previous post, or you don't bother with it at all.

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

                    R Offline
                    R Offline
                    RyJaBy
                    wrote on last edited by
                    #9

                    Thank you very much for your help.

                    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