转换字节从注册表中接收到的字符串 [英] Converting Byte received from the registry to String

查看:100
本文介绍了转换字节从注册表中接收到的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在创造它会监视更改特定的注册表键值,并写入这些更改到一个文本文件中的应用程序的过程。

I'm in the process of creating an application which will monitor specific registry key values for changes and write those changes to a text file.

在present我可以监视的更改,并知道什么时候具体值发生了变化,收集这些值中的数据。我在目前的问题是数据的返回类型为字节,我希望将其转换为字符串最初为显示器,所以我知道它返回正确的值,然后可以保存到一个文本文件中。

At present I can monitor the changes and know when specific values have changed and collect the data held in those values. The problem I'm having at the moment is the return type of the data is Byte and I wish to convert this to String initially for display so I know it returns the right value and then can be saved to a text file.

我所要求的原因是,以后的下一个时间上的用户登录到一个系统将被创建或改变的那些键以匹配previous值。 (如目前正在使用强制配置文件正在做这样的一种方式来保存用户preferences)。

The reason I'm asking is that later on the next time the user logs onto a system those keys will be created or changed to match the previous values. (Were doing this as a way to save user preferences as were currently using mandatory profiles).

如果任何人有任何建议这将是AP preciated。

If anyone has any advice it would be appreciated.

推荐答案

右键我现在已经能够通过存储在注册表值的字节数组,然后加入阵列的每个部分为一个字符串,使用来解决这个下面code:

Right I've now been able to resolve this by storing the registry value in a byte array, then adding each part of the array to a string, using the following code:

RegistryKey key = Registry.Users.OpenSubKey(e.RegistryValueChangeData.KeyPath);

            Byte[] byteValue = (Byte[])key.GetValue(e.RegistryValueChangeData.ValueName);

            string stringValue = "";

            for (int i = 0; i < byteValue.Length; i++)
            {
                stringValue += string.Format("{0:X2} ", byteValue[i]);
            }

感谢所有的建议

Thanks for all the suggestions

这篇关于转换字节从注册表中接收到的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆