vikky
September 27, 2017, 10:15am
1
I want to change IP of the colibri vf61 device through c# code. I have changed the IP Address in registry. But How to save the the registry through C#.
RegistryKey OurKey = Registry.LocalMachine;
OurKey = OurKey.OpenSubKey(@"COMM\ENET2\Parms", true);
foreach (string Keyname in OurKey.GetSubKeyNames())
{
RegistryKey key = OurKey.OpenSubKey(Keyname,true);
key.SetValue("IPAddress", "192.168.1.122", RegistryValueKind.String);
Console.WriteLine(key.GetValue("IPAddress").ToString());
key.Close();
}
vikky
September 27, 2017, 10:56am
2
Ok, I got the answer. just add the code:
ProcessStartInfo startinfo = new ProcessStartInfo();
startinfo.FileName = @"..\..\windows\update.exe";
startinfo.Arguments = "/f";
Process.Start(startinfo);
Actually SaveReg is nothing, just a shortcut of command â\windows\update.exe /fâ .
You may also use the Flush method of RegistryKey to force the system to write the registry.
TJO
September 28, 2017, 9:00am
4
A better way could be to PInvoke the RegFlushKey function in the coredll.dl
[DllImport("coredll.dll", EntryPoint = "RegFlushKey")]
public static extern int RegFlushKey(uint hKey);
// const uint HKEY_LOCAL_MACHINE = 0x80000002
private uint HKey = 0x80000002;
// Call to save the HKLM
RegFlushKey(HKey);