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!




Reply With Quote
