| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 3373 人关注过本帖
标题:求VB修改注册表
只看楼主 加入收藏
dao1975
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2008-9-1
收藏
 问题点数:0 回复次数:7 
求VB修改注册表
我在编一个程序时需要修改注册表的一个值,其类型为REG_BINARY,其值为“91000000”,但不知要怎么写,我写的是这样的:
API函数声明已有
Private Const REG_BINARY = 3&
API函数声明已有,在此我就省了
   dim c as long
   c = “91000000”  
   RegCreateKey HKEY_CURRENT_USER, "Software\Microsoft\Windows\CurrentVersion\Policies\Explorer", hKey
   RegSetValueEx hKey, "NoDriveTypeAutoRun", 0&, REG_BINARY, c, 3
   RegCloseKey hKey

写入后内容就不是如:0000  91 00 00 00了,请高手指点下,只要VB编写的,

  导出的注册文件内容(正确的)是这样的:
  Windows Registry Editor Version 5.00
  [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer]
  "NoDriveTypeAutoRun"=hex:91,00,00,00
搜索更多相关主题的帖子: 注册表 
2008-09-01 07:05
我是菜鸟哦
Rank: 6Rank: 6
等 级:贵宾
威 望:22
帖 子:921
专家分:209
注 册:2007-5-4
收藏
得分:0 
觉得无须声明系统函数直接用shell

然后运行相关的Bcmd代码

[[it] 本帖最后由 我是菜鸟哦 于 2008-9-1 11:28 编辑 [/it]]

偶是菜鸟鸟偶惧WHO?!!!!
2008-09-01 11:19
不说也罢
Rank: 13Rank: 13Rank: 13Rank: 13
等 级:贵宾
威 望:39
帖 子:1481
专家分:4989
注 册:2007-10-7
收藏
得分:0 
仅仅声明常量REG_BINARY 还不行,还必须声明常量HKEY_CURRENT_USER

Private Const REG_BINARY = 3&
Private Const HKEY_CURRENT_USER = &H80000001'就是这一句

   c = "91000000"
   RegCreateKey HKEY_CURRENT_USER, "Software\Microsoft\Windows\CurrentVersion\Policies\Explorer", hKey
   RegSetValueEx hKey, "NoDriveTypeAutoRun", 0&, REG_BINARY, c, [bo]4[/bo]
   RegCloseKey hKey

[[it] 本帖最后由 不说也罢 于 2008-9-1 13:48 编辑 [/it]]

===================================================
讨厌C#的行尾的小尾巴;和一对大括号{ }
===================================================
2008-09-01 13:40
dao1975
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2008-9-1
收藏
得分:0 
楼上说的我全都声明过的,不行的
Private Declare Function RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, lpData As Any, ByVal cbData As Long) As Long
Private Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Private Declare Function RegOpenKeyExA Lib "advapi32.dll" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal ulOptions As Long, ByVal samDesired As Long, phkResult As Long) As Long
Private Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Private Declare Function RegDeleteValue Lib "advapi32.dll" Alias "RegDeleteValueA" (ByVal hKey As Long, ByVal lpValueName As String) As Long


Private Const HKEY_CLASSES_ROOT = &H80000000
Private Const HKEY_CURRENT_USER = &H80000001
Private Const HKEY_LOCAL_MACHINE = &H80000002
Private Const HKEY_USERS = &H80000003
Private Const REG_SZ = 1&
Private Const REG_EXPAND_SZ = 2&
Private Const REG_BINARY = 3&
Private Const REG_DWORD = 4&
Private Const ERROR_SUCCESS = 0&


Private Sub Command1_Click()
Dim hKey As Long
Dim a As Long
 a = "91000000"  
RegCreateKey_
HKEY_CURRENT_USER, "Software\Microsoft\Windows\CurrentVersion\Policies\Explorer",hKey

RegSetValueEx hKey, "NoDriveTypeAutoRun", 0&, REG_BINARY, a, 3

RegCloseKey hKey

End Sub

  以上就是我编的全码,不行的,请高手指点下,网上找不到



   另说下二楼的那位朋友如要用 shell调用 我就不会在此求助了,不用你说我都会,要的是VB写的独立程序

[[it] 本帖最后由 dao1975 于 2008-9-1 15:50 编辑 [/it]]
2008-09-01 15:46
不说也罢
Rank: 13Rank: 13Rank: 13Rank: 13
等 级:贵宾
威 望:39
帖 子:1481
专家分:4989
注 册:2007-10-7
收藏
得分:0 
不会吧?3楼的代码我运行通过了呀?写入后内容就象:0000  91 00 00 00了


你运行3楼的代码后查看注册表项的值是什么啊?

不过你要想实现3楼的代码运行以后导出注册表后"NoDriveTypeAutoRun"=hex:91,00,00,00的话,3楼代码中的变量C的值就不应当是91000000了

[[it] 本帖最后由 不说也罢 于 2008-9-1 18:05 编辑 [/it]]

===================================================
讨厌C#的行尾的小尾巴;和一对大括号{ }
===================================================
2008-09-01 18:00
不说也罢
Rank: 13Rank: 13Rank: 13Rank: 13
等 级:贵宾
威 望:39
帖 子:1481
专家分:4989
注 册:2007-10-7
收藏
得分:0 
再给你一种代码,自已再弄弄吧.运行的结果就是你在顶楼要的"NoDriveTypeAutoRun"=hex:91,00,00,00
Private Declare Function RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, lpData As Any, ByVal cbData As Long) As Long
Private Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long

Const HKEY_CURRENT_USER = &H80000001
Const REG_BINARY = 3

Private Sub Command1_Click()
Dim hKey As Long
Dim ret As Long
Dim bArr(0 To 3) As Byte

bArr(0) = &H91: bArr(1) = &H0: bArr(2) = &H0: bArr(3) = &H0

ret = RegCreateKey(HKEY_CURRENT_USER, "Software\Microsoft\Windows\CurrentVersion\Policies\Explorer", hKey)
RegSetValueEx hKey, "NoDriveTypeAutoRun", 0, REG_BINARY, bArr(0), 4
RegCloseKey hKey
End Sub

===================================================
讨厌C#的行尾的小尾巴;和一对大括号{ }
===================================================
2008-09-01 18:21
dao1975
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2008-9-1
收藏
得分:0 
太谢谢我楼上的这位朋友了,你给的代码完全通过,写入里面后的二进制内容正是我所要 0000 91 00 00 00      .... 在次谢谢你了!
2008-09-02 08:19
不说也罢
Rank: 13Rank: 13Rank: 13Rank: 13
等 级:贵宾
威 望:39
帖 子:1481
专家分:4989
注 册:2007-10-7
收藏
得分:0 
太客气了,无需言谢的

论坛应当有个机制,解决问题的贴子请发贴人做个标记才好

===================================================
讨厌C#的行尾的小尾巴;和一对大括号{ }
===================================================
2008-09-02 19:05
快速回复:求VB修改注册表
数据加载中...
 
   



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

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