如何访问和更新注册表.NET Framework 4.0 [英] How to access & update the registry .NET Framework 4.0

查看:196
本文介绍了如何访问和更新注册表.NET Framework 4.0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将一些VB6注册表访问代码移植到C#.net2010.
我找到了Microsoft.win32.registry类.
问题是试图解决的是在VB代码中,所有键都定义为十六进制值,并且功能相当冗长.它们似乎与我在.NET Framework 4.0上看到的方法不匹配.

任何人都可以为我提供这些函数之间的交叉引用,我是否仍需要为HKEY_CURRENT_USER之类的东西声明HEX值,还是该类的这些属性?
在此先感谢..

I am porting some VB6 registry access code to C#.net 2010.
I have found the Microsoft.win32.registry class.
The problem is am trying to solve is in the VB code all of the Keys are defined as HEX values and the functions are pretty lengthy. they don''t seem to match the methods I''m seeing on .NET Framework 4.0.

Can anyone provide me with a cross reference between these functions and do I still need to declare the HEX values for things like HKEY_CURRENT_USER or are these properties of the class?
thanks in advance..

推荐答案

我不确定您具体指的是哪个函数,但是所有注册表访问函数都在Microsoft.Win32.RegistryKey类中.

Microsoft.Win32.Registry类公开了所有根密钥,例如HKEY_CURRENT_USER,以便您可以将它们称为Registry.CurrentUser(它将检索该根的只读密钥).有了所需的根之后,其余所有功能都将从该键中调用.

RegistryKey成员 [
I am not sure which functions you are specifically referring to, but all the registry access functions are in the Microsoft.Win32.RegistryKey class.

The Microsoft.Win32.Registry class exposes all the root keys such as HKEY_CURRENT_USER so that you can refer to them as Registry.CurrentUser (which will retrieve a read-only key for that root). Once you have the root that you want, all the rest of the functions are called from that key.

RegistryKey members[^]

Did I understand your question correctly?


首先,您似乎在编程中缺少了一些重要的东西.没有十六进制值"或十进制值"之类的东西.有不同整数类型的值,也有字符串.如果字符串形式的整数值,则十六进制或十进制或二进制可以是不同的表示形式.二进制字符串表示形式并不是真正的二进制,因为它每位使用一个字符("0"或"1"),并且此字符占用1或2个字节,具体取决于编码.

您可以使用类Microsoft.Win32.Registry访问Windows注册表.我认为没有人会希望在VB6运行时和此类之间找到对应关系.而且我认为您甚至不需要它.只需阅读以下内容和相关主题即可:
http://msdn.microsoft.com/zh-CN /library/microsoft.win32.registry.aspx [ ^ ].

请了解:此类不是标准库的一部分(.NET库的一部分已通过ECMA和ISO标准化);也不建议使用Windows注册表.应用程序使用注册表确实是一个坏主意.此外,如果仅使用标准库(以及某些非标准库,例如System.Windows.Forms),则代码可以通过Mono( http://msdn.microsoft.com/zh-cn/library/system.configuration.configurationmanager.aspx [ http://msdn.microsoft.com/zh-CN/library/aa730869(v = vs.80).aspx [ http://msdn.microsoft.com/en-us/library /system.environment.specialfolder.aspx [System.Environment.GetFolderPath, http://msdn的新窗口> ^ ]. microsoft.com/en-us/library/14tx8hby.aspx [ ^ ]了解更多信息.

—SA
First of all, it looks like you''re missing something important in programming. There is no such thing as "Hex values" or "decimal values". There are values of different integer types and there are strings. Hex or decimal or binary can be different representation if integer values in the string forms. A binary string representation is not really binary in the sense that it uses one character (''0'' or ''1'') per bit, and this character takes 1 or 2 bytes, depending on encoding.

You can access Windows Registry using the class Microsoft.Win32.Registry. I don''t think anyone would be interested looking for correspondence between VB6 run-time and this class. And I don''t think you even need it. Just read this and related topics: http://msdn.microsoft.com/en-us/library/microsoft.win32.registry.aspx[^].

Please understand: this class is not a part of standard library (part of .NET libraries are standardized by ECMA and ISO); also the use of Windows Registry is completely discouraged. Using the Registry by an application is really a bad idea. Moreover, if you use standard libraries only (and some non-standard ones, such as System.Windows.Forms) your code can work on many platforms, such as Mac, Linux and many more — via Mono (http://en.wikipedia.org/wiki/Mono_(software)[^]). If you use Registry — forget it! — your software is not really portable between different Windows system.

So, there is only one good way — stop using Registry. (Well, you already have my answer on using Registry anyway, so this is a step forward.) What to use instead? Well, one thing is Configuration, see http://msdn.microsoft.com/en-us/library/system.configuration.configurationmanager.aspx[^], another one — settings, see http://msdn.microsoft.com/en-us/library/aa730869(v=vs.80).aspx[^]. Most general advice on using and persisting (writeable) application-specific data is this: you need to use the method System.Environment.GetFolderPath(System.Environment.SpecialFolder) to get write path where you want to store your data. Most typically, you would use System.Environment.GetFolderPath(System.Environment.SpecialFolder.LocalApplicationData). See System.Environment.SpecialFolder, http://msdn.microsoft.com/en-us/library/system.environment.specialfolder.aspx[^] for other folders, System.Environment.GetFolderPath, http://msdn.microsoft.com/en-us/library/14tx8hby.aspx[^] for more information.

—SA


这篇关于如何访问和更新注册表.NET Framework 4.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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