Write to registry using P/Invoke
I need to change a registery value in windowsCE using c# and P/Invoke (RapiDll isn't on there)
I know how to read the key:
private static string ReadRegKey(UIntPtr rootKey, string keyPath, string valueName,string value)
{
IntPtr hKey = IntPtr.Zero;
if (RegOpenKeyEx(rootKey, keyPath, 0, KEY_READ, out hKey) == 0)
{
uint size = 1024;
uint type = 0;
string keyValue = null;
StringBuilder keyBuffer = new StringBuilder();
keyBuffer.Append(value);
if (RegQueryValueEx(hKey, valueName, IntPtr.Zero, ref type, keyBuffer, ref size) == 开发者_开发问答0)
keyValue = keyBuffer.ToString();
RegCloseKey(hKey);
return (keyValue);
}
return (null); // Return null if the value could not be read
}
Can anyone help me with this? (It's for changing the Device name btw)
RegistryKey reg = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\WJST\WLAN", true);
// set value of "CDInsert" to 1
reg.SetValue("CDInsert", 1, RegistryValueKind.DWord);
// get value of "CDInsert"; return 0 if value not found
int value = (int)reg.GetValue("CDInsert", 0);
Why don't you want to use RegistryKey class from Microsoft.Win32 namespace?
http://msdn.microsoft.com/en-us/library/microsoft.win32.registrykey%28v=VS.80%29.aspx
If you intend to write/read/query registry values which are not inside wow6432 node and if you are using framework less than 4.0 then you need RegistryEX kind of P/Invoke dll's
for e.g you are running a 32 bit app on a 64 bit application,due to virtualization the registry would be under 32 bit node.If you need to create it under 64 bit then you need to use these p/invokes
Hope and wish you succes
精彩评论