Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
157 views
in Technique[技术] by (71.8m points)

c# - reading value from registry and storing it in a bin file in a folder

I am writing a C# code. As shown in the image, I need to retrieve the value of a key called LicenseKey (right side of the image) from the registry path HKEY_LOCAL_MACHINE/Software/Avtec, Inc/LicenseKey and store the value in a bin file called pml.bin

Can anyone help me with the code? Thanks in advance.

enter image description here

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Add reference to Microsoft.Win32 API and add the below code.

        RegistryKey key = Registry.LocalMachine;
        RegistryKey dataKey = key.OpenSubKey(@"SoftwareAvtec.IncLicenseKey");
        string licenceKey = dataKey.GetValue("required field name").ToString();

        using (BinaryWriter b = new BinaryWriter(File.Open("file.bin", FileMode.Create)))
        {
            b.Write(licenceKey);
            b.Close();
        }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...