Results 1 to 2 of 2

Thread: How delete in registry keys instead using Regedit?

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2011
    Posts
    15

    How delete in registry keys instead using Regedit?

    Hi, I'm a newbie.
    I have problems about USB device drivers: I can see the driver correctly installed but application says device is not present.
    I solved using Regedit:
    in
    HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\USB

    I have to manually delete the key

    HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\USB\Vid_04d8&Pid_8001

    with all subkeys.

    I've seen there are several examples managing registry keys using vb, but I can't understand how detect if the key is present and how delete it.
    Can anyone explain me?
    Thanks.

  2. #2
    Karen Payne MVP kareninstructor's Avatar
    Join Date
    Jun 2008
    Location
    Oregon
    Posts
    6,714

    Re: How delete in registry keys instead using Regedit?

    Take a look here Accessing the Registry with Visual Basic .NET

    Read the path to PBrush if the key is located.
    Code:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim regVersion As RegistryKey
        regVersion = Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\pbrush.exe", True)
        If regVersion Is Nothing Then
            MessageBox.Show("pbrush key does not exists")
        Else
            ' read default value
            MessageBox.Show(String.Concat("Path to pbrush is ", regVersion.GetValue("").ToString))
        End If
    End Sub
    To delete a key you need to run your app as an administerator for keys under HKLM

    See Permission

    In this example KSG1 is a key I created for this demo
    Code:
    Dim regVersion As RegistryKey
    regVersion = Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths", True)
    If regVersion Is Nothing Then
        MessageBox.Show("KSG1 does not exists")
    Else
        Try
            regVersion.DeleteSubKey("KSG1")
            MessageBox.Show("Deleted key")
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End If

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width