Just as there is a startup folder for all users and the current user, there are startups in the
registry as well. The startups in the registry start before the ones in the startup folders. They are located in two places. The equivalent of the user startup folder in the registry is in HKEY_CURRENT_USER. Items in that registry startup start only for that user. The equivalent of the all user startup folder is the HKEY_LOCAL_MACHINE startup, which start for all users. There are also RunOnce startups in each of those places as well. A RunOnce startup will, as it's name says, run only on the next reboot, and will be deleted as a startup after that.
HKCU startupsThe HKCU startups are located in a registry key under the HKCU base key. The exact path of that key is
HKCU\Software\Microsoft\Windows\CurrentVersion\Run\. To access that registry key in your code, use
vb
My.Computer.Registry.CurrentUser.OpenSubKey("Software").OpenSubKey("Microsoft") _
.OpenSubKey("Windows").OpenSubKey("CurrentVersion").OpenSubKey("Run")
That will return a
Microsoft.Win32.RegistryKey that equals the HKCU run key.
HKCU RunOnceThe HKCU run once's are located in almost the same place as the normal startups, the only only difference is they are located in a key called RunOnce instead of Run. The full path of the HKCU runonce is
HKCU\Software\Microsoft\Windows\CurrentVersion\RunOnce\.
HKLM startupsThe HKLM startups are located in the same path at the HKCU startups, except they are under the base key HKLM. The full path of the HKLM startups is
HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run\. To access that key in your code, use
vb
My.Computer.Registry.LocalMachine.OpenSubKey("SOFTWARE").OpenSubKey("Microsoft") _
.OpenSubKey("Windows").OpenSubKey("CurrentVersion").OpenSubKey("Run")
The HKLM starups can be accessed and edited in the same way as the HKCU startups, the only difference between them is that they one is all user and one is current user. We will talk about how to edit registry keys later.
HKLM RunOnceThe HKLM run once's can be access in the same way as the HKCU run once's. The full path of the HKLM run once's is
HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce\.
HKLM RunServicesThis is something we have not talked about yet. Unlike the HKCU key, the HKLM key has a RunServices key. The path of the RunServices key is
HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\RunServices\. Don't confuse services with standard startups, because they are different, and for someone who is just learning about registry startups, you probably shouldn't mess with Services until you know a bit more about them.
Learn more about services here.Editing the Microsoft.Win32.RegistryKey classThere are many methods in the registrykey class. Here, we will only talk about the ones that could possibly be of use when the registrykey is a startup key. These methods are
SetValueUsage: This can be used to edit an existing startup
Syntax:
vb
RegistryKeyName.SetValue(StartupName As String, StartupPath As String)
GetValueUsage: This can be used to get a path to an existing startup
Syntax:
vb
RegistryKeyName.GetValue(StartupName As String) As Object
ValueCount (property)Usage: Read-only property that shows how many startups are in the startup key
Syntax:
vb
RegistryKeyName.ValueCount() As Integer
GetValueNamesUsage: This can be used to get the names of all the startups in the startup key
Syntax:
vb
RegistryKeyName.GetValueNames() As String()
DeleteValueUsage: This can be used to delete an existing startup
Syntax:
vb
RegistryKeyName.DeleteValue(StartupName As String)