Results 1 to 13 of 13

Thread: Start Program At Startup With Registry

Threaded View

  1. #1

    Thread Starter
    Lively Member kshadow22's Avatar
    Join Date
    Dec 2014
    Location
    Kentucky
    Posts
    95

    Start Program At Startup With Registry

    I am currently trying to get my program to start up at Windows Startup. However, every code I create or find, I get errors thrown at me. I can't seem to get this to work no matter how many times I change my codes. Could someone please help me?

    Here is my code:

    Code:
    Imports Microsoft.Win32
    Public Class Form1
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim regkey As Microsoft.Win32.RegistryKey
            Dim Keyname As String = "SOFTWARE\Microsoft\Windows*\CurrentVersion\Run" 'Registrypath
            Dim ValueName As String = Application.ProductName 'Program name
            Dim Value As String = Application.ExecutablePath
            'Create Startup
            regkey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(Keyname, True)
            regkey.SetValue(ValueName, Value, RegistryValueKind.String)
        End Sub
    End Class

    Here is the error that is thrown at me every time I try to run the function:
    An unhandled exception of type 'System.NullReferenceException' occurred in WindowsApplication3.exe

    Additional information: Object reference not set to an instance of an object.


    How can I fix this? I know this should have been easy and fairly simple to do. I've been trying to work just this one function for hours. Any help would be greatly appreciated!
    Last edited by kshadow22; Feb 8th, 2016 at 04:33 PM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width