| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1231 人关注过本帖
标题:急!急!注册表二进制数据 读取不了问题!
只看楼主 加入收藏
rryr
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2006-7-5
收藏
 问题点数:0 回复次数:1 
急!急!注册表二进制数据 读取不了问题!

是对 代理服务器 键值的修改 "Software\Microsoft\Windows\CurrentVersion\Internet Settings\Connections" 下的 DefaultConnectionSettings,修改可以改IE代理,但就是读取显示"尝试读取或写入受保护的内存。这通常指示其他内存已损坏",求大大们帮帮
本人菜鸟一个,没删注释! Text1.Text的内容为 DefaultConnectionSettings
模块:
Public Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias "RegOpenKeyExA" (ByVal hKey As Integer, ByVal lpSubKey As String, ByVal ulOptions As Integer, ByVal samDesired As Integer, ByRef phkResult As Integer) As Integer
'读取注册表的函数

Public Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" ( _
ByVal hKey As Integer, _
ByVal lpValueName As String, _
ByVal lpReserved As Integer, _
ByVal lpType As Integer, _
ByRef lpData As String, _
ByRef ByreflpcbData As Integer _
) As Integer
' Note that if you declare the lpData parameter as String, you must pass it By Value.
'设置注册表的函数
Public Declare Function RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal hKey As Integer, ByVal lpValueName As String, ByVal Reserved As Integer, ByVal dwType As Integer, ByVal lpData As String, ByVal cbData As Integer) As Integer ' Note that if you declare the lpData parameter as String, you must pass it By Value.
'关闭注册表的函数
Public Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Integer) As Integer
Public Declare Function RegDeleteKey Lib "advapi32.dll" Alias "RegDeleteKeyA" (ByVal hKey As Integer, ByVal lpSubKey As String) As Integer
Public Declare Function RegDeleteValue Lib "advapi32.dll" Alias "RegDeleteValueA" (ByVal hKey As Integer, ByVal lpValueName As String) As Integer
Public Const HKEY_CURRENT_USER = &H80000001
Public Const sKey = "Software\Microsoft\Windows\CurrentVersion\Internet Settings\Connections"

'这句声明表示是以二进制方式打开注册表
Public Const REG_BINARY = 3
Public Const REG_dword = 4&
Public Const internet_option_proxy = 38
Public Const INTERNET_OPTION_SETTINGS_CHANGED = 39
'下面的这些声明是操作注册表的权限,最后一个声明 KEY_ALL_ACCESS 就是把所有的权限都打开了
Public Const STANDARD_RIGHTS_ALL = &H1F0000
Public Const KEY_QUERY_VALUE = &H1
Public Const KEY_SET_VALUE = &H2
Public Const KEY_CREATE_SUB_KEY = &H4
Public Const KEY_ENUMERATE_SUB_KEYS = &H8
Public Const KEY_NOTIFY = &H10
Public Const KEY_CREATE_LINK = &H20
Public Const SYNCHRONIZE = &H100000
Public Const KEY_ALL_ACCESS = ((STANDARD_RIGHTS_ALL Or KEY_QUERY_VALUE Or _
KEY_SET_VALUE Or KEY_CREATE_SUB_KEY Or KEY_ENUMERATE_SUB_KEYS Or KEY_NOTIFY Or _
KEY_CREATE_LINK) And (Not SYNCHRONIZE))

下面是具体写读注册表:问题在1111111111 标记处
Public Sub setproxy_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles setproxy.Click
'hKey接受打开注册表项的句柄,lenData接受要获取的数据的长度
Dim hKey As Integer, lenData As Integer
'以所有可操作的权限打开注册表,并把打开的注册表的句柄保存到 hKey 变量中
RegOpenKeyEx(HKEY_CURRENT_USER, sKey, 0, KEY_ALL_ACCESS, hKey)
'获取指定连接的数据长度放到 lenData 中
RegQueryValueEx(hKey, Trim(Text1.Text), 0, 0, vbNullString, lenData)
Debug.Write(lenData)
'分配一个长度是 lenData 的字节型变量数组存放数据。存取注册表中二进制的数据必须用字节型变量,也就是 Byte 类型的变量
Dim bArr(lenData - 1) As Byte
'以二进制的方式获取 lenData 长度的数据并保存到 bArr 数组中
11111111111:
RegQueryValueEx(hKey, Trim(Text1.Text), 0, REG_BINARY, bArr(0), lenData)
'如果使用代理服务器
bArr(8) = 3
Dim i As Long, j As Long, s As String
s = Trim(proxyT1.Text) '变量等于去掉填写代理服务器地址和端口号的文本框中内容的空格的内容
i = Len(s) '获取去掉空格后的代理服务器地址和端口号的长度,以供后面写入注册表中使用
bArr(12) = i '第十三个数组存放代理服务器地址和端口号的长度
For j = 1 To i '循环范围是从1到代理服务器地址和端口号的长度
bArr(j + 15) = Asc(Mid(s, j, 1)) '依次取出代理服务器地址和端口号的单个字符并且把字符转换成字符的ASCII代码,并且依次放到从第17个数组开始的数组
Next j
'把设置后的数组,也就是要设置的信息放到注册表中
RegSetValueEx(hKey, Trim(Text1.Text), 0, REG_BINARY, bArr(0), UBound(bArr) + 1)
'关闭注册表
RegCloseKey(hKey)
End Sub

FR2RbtaJ.rar (758 Bytes) 急!急!注册表二进制数据 读取不了问题!


搜索更多相关主题的帖子: 二进制 注册表 内存 Microsoft 代理服务器 
2007-05-22 22:42
为记忆上锁
Rank: 3Rank: 3
等 级:新手上路
威 望:8
帖 子:96
专家分:0
注 册:2007-4-27
收藏
得分:0 
怎么不用 .net 自带的类访问注册表,而要用api ?

没有你得不到滴,只有你不想要滴
2007-05-23 20:27
快速回复:急!急!注册表二进制数据 读取不了问题!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016927 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved