- 1、本文档共5页,可阅读全部内容。
- 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
VB读写注册表
VB读写注册表今天,我们将制作一个能读写注册表的程序。程序运行后,可以选择要添加、删除、修改或查询的键和键值。程序运行结果如图所示。运行结果技术要点操纵注册表的API函数添加、删除键和键值查询键值实现过程新建项目打开Visual Studio.NET,选择“新建项目”,在项目类型窗口中选择“Visual Basic项目”,在模板窗口中选择“Windows应用程序”,在名称域中输入“Rwregister”,然后选择保存路径。单击“确认”。添加控件和模块向当前窗体上添加两组Group控件,每组上有两个RadioButton选项按钮,将它们分别做成控件数组;四个Label控件,用作说明之用;一个ComboBox控件和三个TextBox控件,分别用于输入相应的子键、键名和键值;四个Button控件用于实现相应的功能。设置属性将Label控件、Button按钮、RadioButton控件的Text属性设置为和界面一致。将TextBox控件的Text属性清空。添加代码由于本实例使用的API函数和常数比较多,在此仅列出主要的声明部分。 这是在模块中添加的代码Option Strict OffPublic Declare Function RegCreateKeyEx Lib advapi32.dll Alias RegCreateKeyExA (ByVal hKey As Long, ByVal lpSubKey As String, ByVal Reserved As Long, ByVal lpClass As String, ByVal dwOptions As Long, ByVal samDesired As Long, lpSecurityAttributes As SECURITY_ATTRIBUTES, phkResult As Long, lpdwDisposition As Long) As LongPublic Declare Function RegDeleteKey Lib advapi32.dll Alias RegDeleteKeyA (ByVal hKey As Long, ByVal lpSubKey As String) As LongPublic Declare Function RegDeleteValue Lib advapi32.dll Alias RegDeleteValueA (ByVal hKey As Long, ByVal lpValueName As String) As LongPublic Declare Function RegCloseKey Lib advapi32.dll (ByVal hKey As Long) As LongPublic Declare Function RegOpenKey Lib advapi32.dll Alias RegOpenKeyA (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As LongPublic Declare Function RegSetValue Lib advapi32.dll Alias RegSetValueA (ByVal hKey As Long, ByVal lpSubKey As String, ByVal dwType As Long, ByVal lpData As String, ByVal cbData As Long) As LongPublic Type SECURITY_ATTRIBUTES nLength As Long lpSecurityDescriptor As Long bInheritHandle As LongEnd Type 设置键值Public Function SetKeyValue(ByRef lPredefinedKey As Integer, ByRef sKeyName As String, ByRef sValueName As String, ByRef vValueSetting As Object, ByRef lValueType As Integer) As Object Dim lRetVal As Integer Dim hKey As IntegerlRetVal = RegOpenKeyEx(lPredefinedKey, sKeyName, 0, KEY_ALL_ACCESS, hKey) lRetVal = SetValueEx(hKey, sValueName, lValueType, vValueSetting) Re
文档评论(0)