[RESOLVED] Read Startup Program In Regsity and Put in ListView
I'm trying trying to add a feature to a program i'm working on that puts the start up programs on a system into a listview.
The start up items are stored in the following registry location:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run
What I would like to do is read the Program Name value under the Name Column in the registry and the Data Value under the Data value and put these values into the listview in two seperate columns like Msconfig utility see the screen shot.
I'm familiar with working with the registry in .NET, but I can't seem to get this to work. I believe I would need to loop through each registyvaluename under this key and get the name and value.
Thanks,
Last edited by TechMe.NET; Jan 27th, 2012 at 02:31 PM.
This is the raw code where GetValueNames provides you with just that names and then use GetValue for each one. Place the pairs into a container that you can sort A-Z, done.
Does not cover Default item
Code:
Dim regKey As RegistryKey
regKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Run", False)
Dim Names = regKey.GetValueNames
For Each Item In Names
Console.WriteLine("{0} = {1}", Item, regKey.GetValue(Item))
Next
regKey.Close()
Re: Read Startup Program In Regsity and Put in ListView
Using a DataGridView
Code:
Private Sub PopulateRegDemo()
Dim dt As New DataTable
dt.Columns.AddRange(New DataColumn() _
{ _
New DataColumn("StartUpItem", GetType(System.String)), _
New DataColumn("RunCommand", GetType(System.String)) _
} _
)
Dim regKey As Microsoft.Win32.RegistryKey
regKey = Microsoft.Win32.Registry.LocalMachine _
.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Run", False)
Dim Names = regKey.GetValueNames
For Each Item In Names
dt.Rows.Add(New Object() {Item, regKey.GetValue(Item).ToString.Replace(Chr(34), "")})
Next
regKey.Close()
dt.DefaultView.Sort = "StartUpItem"
DataGridView1.DataSource = dt.DefaultView
End Sub