Hi, RegistryKey Class doesn't extend to the shared registry locations, if you are writing a 64bit program and need to update the registry under the HKLM\Software\wow6432Node or HKCU\Software\wow6432Node you have to use advapi.dll api calls. .Net 4.0 apparently contains these features in the RegistryKey Class however I am stuck on .Net 3.5 for the time being.
Chris. On 16 June, 17:39, "Tony.Techex" <[email protected]> wrote: > Just curious, any reason why your not using RegistryKey class? > > ~Tony > > On Jun 16, 8:22 am, 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.
