注册表操作!!windows2000操作

kstczzyals 2004-04-30 08:25:12
比如我想更改HKEY_CURRENT_USER\Software\Webzen\Mu\Config
里的一个Resolution子键 REG_DWORD 值是0x0000000
我想通过VC API函数更改为0x00000001
应该怎么做。请帮兄弟写详细一点!!!!!!
...全文
120 6 点赞 打赏 收藏 举报
写回复
6 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
dongge2000 2004-05-02
Public Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias "RegOpenKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal ulOptions As Long, ByVal samDesired As Long, phkResult As Long) As Long
Public Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Public 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 ' Note that if you declare the lpData parameter as String, you must pass it By Value.
Public Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, lpData As Any, lpcbData As Long) As Long ' Note that if you declare the lpData parameter as String, you must pass it By Value.
Public Declare Function RegDeleteValue Lib "advapi32.dll" Alias "RegDeleteValueA" (ByVal hKey As Long, ByVal lpValueName As String) As Long
Public Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long

Public Const HKEY_CLASSES_ROOT = &H80000000
Public Const HKEY_CURRENT_USER = &H80000001
Public Const HKEY_LOCAL_MACHINE = &H80000002
Public Const HKEY_USERS = &H80000003
Public Const HKEY_PERFORMANCE_DATA = &H80000004
Public Const HKEY_CURRENT_CONFIG = &H80000005

Public Const REG_SZ = 1
Public Const REG_EXPAND_SZ = 2
Public Const REG_BINARY = 3 ' Free form binary
Public Const REG_DWORD = 4 ' 32-bit number

Enum iHKEY
KEY_CLASSES_ROOT = &H80000000
KEY_CURRENT_USER = &H80000001
KEY_LOCAL_MACHINE = &H80000002
KEY_USERS = &H80000003
KEY_PERFORMANCE_DATA = &H80000004
KEY_CURRENT_CONFIG = &H80000005
End Enum

Enum iTYPE
SZ = 1
EXPAND_SZ = 2
Binary = 3
DWORD = 4
End Enum

Public Function REG_Write(ByVal inHKEY As iHKEY, ByVal inPath As String, ByVal inName As String, ByVal inType As iTYPE, ByVal inText As String) As Long
'On Error Resume Next
Dim hKey As Long
Dim DataSize As Long
Dim ret As Long

DataSize = Len(inText) + 1

RegCreateKey inHKEY, inPath, hKey
If inType = 4 Then GoTo SetLong

RegSetValueEx hKey, inName, 0, inType, ByVal inText, DataSize
RegCloseKey hKey
Exit Function
SetLong:
inText = CLng(inText)
RegSetValueEx hKey, inName, 0, inType, inText, DataSize
RegCloseKey hKey
End Function

Public Function REG_Read(ByVal inHKEY As iHKEY, ByVal inPath As String, ByVal inName As String, ByVal inType As iTYPE) As String
'On Error Resume Next
Dim hKey As Long
Dim rSize As Long
Dim ret As Long
Dim OutTxt As String

ret = RegOpenKeyEx(inHKEY, inPath, 0, 0, hKey)
ret = RegQueryValueEx(hKey, inName, 0, inType, vbNullString, rSize)
OutTxt = String(rSize, Chr(0))
ret = RegQueryValueEx(hKey, inName, 0, inType, ByVal OutTxt, rSize)
OutTxt = Left(OutTxt, InStr(OutTxt, Chr(0)))
REG_Read = OutTxt
RegCloseKey hKey
End Function

Public Function REG_Del(ByVal inHKEY As iHKEY, ByVal inPath As String, ByVal inName As String) As Boolean
On Error GoTo 1
Dim hKey As Long
RegOpenKeyEx inHKEY, inPath, 0, 0, hSubKey
RegDeleteValue hKey, inName
RegCloseKey hKey
Exit Function
1:
REG_Del = False
End Function
  • 打赏
  • 举报
回复
BitBlt 2004-05-02
呵,为什么把Call errlog注掉了?
帖出来瞧瞧。
  • 打赏
  • 举报
回复
chinaren502 2004-05-02
Public Declare Function RegCloseKey Lib "advapi32.dll" (ByVal Hkey As Long) As Long
Public Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal Hkey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Public 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


Function SaveDword(ByVal Hkey As Long, ByVal strPath As String, ByVal strValueName As String, ByVal lData As Long)
'EXAMPLE"
'
'Call SaveDword(HKEY_CURRENT_USER, "HKEY_CURRENT_USER\Software\Webzen\Mu\Config", "Dword", "0x00000001")
'
'
Dim lResult As Long
Dim keyhand As Long
Dim r As Long
r = RegCreateKey(Hkey, strPath, keyhand)
lResult = RegSetValueEx(keyhand, strValueName, 0&, REG_DWORD, lData, 4)
'If lResult <> error_success Then
' Call errlog("SetDWORD", False)
r = RegCloseKey(keyhand)
End Function
  • 打赏
  • 举报
回复
XmagicX 2004-05-02
奇迹的东东,呵呵,改注册表用几个API可以搞定了
  • 打赏
  • 举报
回复
BitBlt 2004-05-01
这个问题值100分?
  • 打赏
  • 举报
回复
BitBlt 2004-05-01
Dim hk As Long
RegCreateKey HKEY_CURRENT_USER, "Software\Webzen\Mu\Config", hk
RegSetValueEx hk, "Resolution", 0&, REG_DWORD, &H1&, 4
RegCloseKey hk
  • 打赏
  • 举报
回复
相关推荐
发帖
控件
加入

1430

社区成员

VB 控件
申请成为版主
帖子事件
创建了帖子
2004-04-30 08:25
社区公告
暂无公告