当前位置: 动力学知识库 > 问答 > 编程问答 >

c# - Looking for a recommendation for inserting value to registry

问题描述:

i try to insert value to registry in C# like this:

RegistryKey key;

key = Registry.CurrentUser.CreateSubKey("HKEY_LOCAL_MACHINE\\Drivers\\BuiltIn\\Touch");

key.SetValue("InitialState", 0x4, RegistryValueKind.DWord);

but nothing happand

when i insert by hand under HKEY_LOCAL_MACHINE\\Drivers\\BuiltIn\\Touch

i insert value 00000004 (Hexidecima) it works

how to do it right ?

网友答案:

You have a clear error in your statement

You try to use the CurrentUser RegistryKey to write in the LocalMachine registry hive

RegistryKey key;
key = Registry.LocalMachine.CreateSubKey("Drivers\\BuiltIn\\Touch");
key.SetValue("InitialState", 0x4, RegistryValueKind.DWord);
网友答案:

Try closing the key: key.Close(); If I remember correctly, the register is not updated until you call close(). Here's MSDN: MSDN Add Registry Key

分享给朋友:
您可能感兴趣的文章:
随机阅读: