Hey all,
Have access to VS 2010 through work and having a bit of a play. Wouldn't call myself an expert and need some help please. I'm trying to create a small program to delete a selected registry key from a list. Am using a checked list box and 2 buttons. Also have 2 labels on the form but just using them as a visual check as to what the string says.

The program starts alright and gives the list of installed software from Group Policy. I'm having the problem deleting the ticked item. If anyone could suggest code I would be grateful. Here is the code I'm using. I think the problem is when it comes to the .deletesubkey line and what I have entered.

Imports Microsoft.Win32

Public Class Form1
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Dim _RegistryKey As Microsoft.Win32.RegistryKey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\AppMgmt")
For Each _KeyName As String In _RegistryKey.GetSubKeyNames()
Using SubKey As Microsoft.Win32.RegistryKey = _RegistryKey.OpenSubKey(_KeyName)
Dim _Software As String
_Software = DirectCast(SubKey.GetValue("GPO Name"), String)
CheckedListBox1.Items.Add(_Software)
End Using
Next
End Sub

Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
Me.Close()
End Sub

Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
Label1.Text = CheckedListBox1.SelectedItem.ToString()
End Sub

Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim _RegistryKey As Microsoft.Win32.RegistryKey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\AppMgmt")
For Each key As String In CheckedListBox1.CheckedItems
For Each _KeyName As String In _RegistryKey.GetSubKeyNames()
Dim regKey As RegistryKey
regKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\AppMgmt")
Label1.Text = regKey.ToString
Label2.Text = _KeyName
regKey.DeleteSubKey(_KeyName)
regKey.Close()
Next
Next
End Sub
End Class
0 Comments   [ + ] Show Comments

Comments

Please log in to comment

There are no answers at this time
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.

Answers

Answer this question or Comment on this question for clarity