Home All Groups Group Topic Archive Search About

Error on deleting registry value

Author
28 Nov 2006 1:53 AM
Brian8568
I'm doing something wrong.  I'm trying to delete a registry value with
the following code VB 2005 Express:

Dim oReg As Microsoft.Win32.RegistryKey
        oReg =
My.Computer.Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run")
        Try
            oReg.DeleteValue("AlcWzrd")
            Debug.Print("Successfully Delete Registry Key AlcWzrd")
        Catch ex As Exception
            Debug.Print(ex.ToString)
        Finally
            oReg.Close()
        End Try


This fails with:

A first chance exception of type 'System.UnauthorizedAccessException'
occurred in mscorlib.dll.
Cannot write to the registry key.

I'm running this under an admin account and I can add and remove this
key in RegEdit.  What am I doing wrong?

Author
28 Nov 2006 2:01 AM
Herfried K. Wagner [MVP]
<Brian8***@gmail.com> schrieb:
> My.Computer.Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run")

Replace "\\" with "\".

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://dotnet.mvps.org/dotnet/faqs/>
Author
28 Nov 2006 2:44 AM
Brian8568
I've tried both ways.
My.Computer.Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Run")
doesn't work either.



On Nov 27, 9:01 pm, "Herfried K. Wagner [MVP]"
<hirf-spam-me-h...@gmx.at> wrote:
Show quoteHide quote
> <Brian8***@gmail.com> schrieb:
>
> > My.Computer.Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run")Replace "\\" with "\".
>
> --
>  M S   Herfried K. Wagner
> M V P  <URL:http://dotnet.mvps.org/>
>  V B   <URL:http://dotnet.mvps.org/dotnet/faqs/>
Author
28 Nov 2006 2:58 AM
FishingScout
That OpenSubKey opens the key as read-only.

Try this:

My.Computer.Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Run",
True )


Brian8***@gmail.com wrote:
Show quoteHide quote
> I've tried both ways.
> My.Computer.Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Run")
> doesn't work either.
>
>
>
> On Nov 27, 9:01 pm, "Herfried K. Wagner [MVP]"
> <hirf-spam-me-h...@gmx.at> wrote:
> > <Brian8***@gmail.com> schrieb:
> >
> > > My.Computer.Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run")Replace "\\" with "\".
> >
> > --
> >  M S   Herfried K. Wagner
> > M V P  <URL:http://dotnet.mvps.org/>
> >  V B   <URL:http://dotnet.mvps.org/dotnet/faqs/>
Author
28 Nov 2006 3:08 AM
FishingScout
In addition, I think you should call DeleteSubKey rather than
DeleteValue to delete a key.

FishingScout wrote:
Show quoteHide quote
> That OpenSubKey opens the key as read-only.
>
> Try this:
>
> My.Computer.Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Run",
> True )
>
>
> Brian8***@gmail.com wrote:
> > I've tried both ways.
> > My.Computer.Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Run")
> > doesn't work either.
> >
> >
> >
> > On Nov 27, 9:01 pm, "Herfried K. Wagner [MVP]"
> > <hirf-spam-me-h...@gmx.at> wrote:
> > > <Brian8***@gmail.com> schrieb:
> > >
> > > > My.Computer.Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run")Replace "\\" with "\".
> > >
> > > --
> > >  M S   Herfried K. Wagner
> > > M V P  <URL:http://dotnet.mvps.org/>
> > >  V B   <URL:http://dotnet.mvps.org/dotnet/faqs/>
Author
28 Nov 2006 3:14 AM
Brian8568
Bingo!  Thank you.

Show quoteHide quote
On Nov 27, 9:58 pm, "FishingScout" <fishingsc***@comcast.net> wrote:
> That OpenSubKey opens the key as read-only.
>
> Try this:
>
> My.Computer.Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Run",
> True )
>
> Brian8***@gmail.com wrote:
> > I've tried both ways.
> > My.Computer.Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Run")
> > doesn't work either.
>
> > On Nov 27, 9:01 pm, "Herfried K. Wagner [MVP]"
> > <hirf-spam-me-h...@gmx.at> wrote:
> > > <Brian8***@gmail.com> schrieb:
>
> > > > My.Computer.Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run")Replace "\\" with "\".
>
> > > --
> > >  M S   Herfried K. Wagner
> > > M V P  <URL:http://dotnet.mvps.org/>
> > >  V B   <URL:http://dotnet.mvps.org/dotnet/faqs/>