Visual Basic .NET: Deleting a Registry Value failed - Printable Version -Shoutbox (https://shoutbox.menthix.net) +-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58) +--- Forum: Skype & Technology (/forumdisplay.php?fid=9) +---- Forum: Tech Talk (/forumdisplay.php?fid=17) +----- Thread: Visual Basic .NET: Deleting a Registry Value failed (/showthread.php?tid=84790) Visual Basic .NET: Deleting a Registry Value failed by ryxdp on 07-12-2008 at 08:21 AM
This is what I've got: vbnet code: But it's telling me the value doesn't exist, when it clearly does. Why is this? I've tried stripping the HKEY_CURRENT_USER off it, to no avail, it still thinks the value isn't there. I must be pretty blind to see through it; what am I doing wrong? Thanks in advance =) RE: Visual Basic .NET: Deleting a Registry Value failed by Matti on 07-12-2008 at 10:09 AM
I don't have much (read: as good as no) experience with VB.NET, but here are my thoughts: RE: RE: Visual Basic .NET: Deleting a Registry Value failed by ryxdp on 07-12-2008 at 10:16 AM
quote: hmm...I'm not thinking straight..."testingkey" should be "testingval" instead. And yes, I've tried removing the HKEY_CURRENT_USER but it doesn't appear to do anything helpful to me anyway. RE: Visual Basic .NET: Deleting a Registry Value failed by CookieRevised on 07-12-2008 at 02:55 PM
I don't have much (read: as good as no) experience with VB.NET either, but here are my thoughts (taken from the MSDN library): quote:for starters, is My.Computer.Registry.CurrentUser defined as a proper RegistryKey object? Second, if "testingval" is a value, you should not add the last backslash (you shouldn't even add it if it is a subkey, I think). Second, you need to open that key first before you can delelete the value "testingval"... See DeleteValue eg: ' Creates a subkey under HKCU named "Test9999" Dim test9999 As RegistryKey = Registry.CurrentUser.CreateSubKey("Test9999") ' Thus not: ' Registry.CurrentUser.CreateSubKey("HKEY_CURRENT_USER\Test9999\") I think Dim testSettings As RegistryKey = test9999.CreateSubKey("TestSettings") testSettings.SetValue("ID", 123) testSettings.Close() ' Deletes the newly created "id" value under the "HKCU\Test9999\TestSettings\" key. Assuming test9999 is a proper defined RegistryKey object. testSettings = test9999.OpenSubKey("TestSettings", True) testSettings.DeleteValue("id") testSettings.Close() Full example code is given on the MSDN library::RegistryKey Class RE: Visual Basic .NET: Deleting a Registry Value failed by ryxdp on 07-13-2008 at 12:26 AM
It still thinks the value doesn't exist. I must have missed something in the code you gave me, Cookie. vbnet code: RE: RE: Visual Basic .NET: Deleting a Registry Value failed by pollolibredegrasa on 07-13-2008 at 01:48 AM
This code works for me, and should get you started... code:You can then go on and use stuff like code:etc... A couple of other things I've noticed. First, code:Here you've already opened HKEY_CURRENT_USER, by stating it again you make it look for a subkey called HKEY_CURRENT_USER, which is one reason this line probably doesn't work. Secondly, you used 2 If statements in a row: code:If your code worked and changed the correct values, your first If statement would change a value to 0. Immediately after that your second If statement would also be executed and change it back to 1 (because the value is now 0). You should change to an If..Else statement or add an Exit Sub in your Ifs to avoid this. Hope this helps RE: Visual Basic .NET: Deleting a Registry Value failed by ryxdp on 07-13-2008 at 05:11 AM
Thanks, it works perfectly now. I did originally have an Else in there, but I don't know why I removed it... vbnet code: |