/build/static/layout/Breadcrumb_cap_w.png

Visual Studio 2010, VB and deleting from registry.

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

Answers (0)

Be the first to answer this question

Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.

Don't be a Stranger!

Sign up today to participate, stay informed, earn points and establish a reputation for yourself!

Sign up! or login

Share

 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ