I have UAC switched off however I will run the code you mentioned to see if that sheds any more light on the situation. thanks.
Chris On 17 June, 06:00, ThanderMaX <[email protected]> wrote: > The error you are getting is due to UAC permission error. Run the > program using Administrator mode. > > If you still get the same error try this : > > using System.ComponentModel; > > int ret = RegOpenKeyEx(hKey, keyPath, 0, KEY_ALL_ACCESS | > KEY_WOW64_32KEY, out hKey); > if (ret != 0) > { > string OSerrorMessage = new Win32Exception(ret).Message; > > } > > BTW, the following link mentions that any 32 bit application's > registry access will be redirected to wow6432node by windows > :http://www.windowsitpro.com/article/internals-and-architecture/what-s... > > On Jun 16, 8:22 pm, Chris McClintock <[email protected]> wrote: > > > > > Hi, I am having problems with RegDeleteKeyEx function available in > > advapi.dll on Win7 64bit and c# - basically i am trying to delete a > > value from HKLM\Software\Wow6432Node\Test but cannot figure out why I > > am getting error_success=2 (file not found I believe) when it should > > be 0 and the reg value not being deleted...here comes the code....: > > > I have the following in a codefile to try and delete the reg value; > > > regload rl = new regload(); > > bool del = rl.WoWDel("HKLM", @"Software\Test", "TESTValue"); > > > This being the main code: > > > using System; > > using System.Runtime.InteropServices; > > using System.Text; > > using Microsoft.Win32; > > > namespace AdvRegistry > > { > > public class regload > > { > > > [DllImport("advapi32.dll", CharSet = CharSet.Auto)] > > public static extern int RegOpenKeyEx( > > UIntPtr hKey, > > string subKey, > > int ulOptions, > > int samDesired, > > out UIntPtr hkResult); > > > [DllImport("advapi32.dll", EntryPoint = "RegDeleteKeyEx", > > SetLastError = true)] > > public static extern int RegDeleteKeyEx( > > UIntPtr hKey, > > string lpSubKey, > > int samDesired, > > int Reserved); > > > [DllImport("advapi32.dll", SetLastError = true)] > > public static extern int RegCloseKey( > > UIntPtr hKey); > > > public static int KEY_WOW64_64KEY = 0x0100; > > public static int KEY_WOW64_32KEY = 0x0200; > > public static int KEY_READ = 0x20019; > > public static int KEY_WRITE = 0x20006; > > public static int KEY_ALL_ACCESS = 0xF003F; > > public static UIntPtr HKEY_LOCAL_MACHINE = new > > UIntPtr(0x80000002u); > > public static UIntPtr HKEY_CURRENT_USER = new > > UIntPtr(0x80000001u); > > > public bool WoWDel(string RegRoot, string RegPath, string > > RegItem) > > { > > if (RegRoot == "HKCU") DelWowReg(HKEY_CURRENT_USER, > > RegPath, RegItem); > > else if (RegRoot == "HKLM") DelWowReg(HKEY_LOCAL_MACHINE, > > RegPath, RegItem); > > else return false; > > return true; > > } > > > private static int DelWowReg(UIntPtr hKey, string keyPath, > > string valueName) > > { > > int i = 9999; > > > if (RegOpenKeyEx(hKey, keyPath, 0, KEY_ALL_ACCESS | > > KEY_WOW64_32KEY , out hKey) == 0) > > { > > > // int wlength = value.Length + 1; > > i = RegDeleteKeyEx(hKey, valueName, KEY_WOW64_32KEY, > > 0); > > RegCloseKey(hKey); > > return i; > > > } > > return i; > > } > > > } > > > } > > > Where did I go wrong? > > > many thanks for the help, Chris.
