永发信息网

VB问题,请大虾指点!!

答案:1  悬赏:0  手机版
解决时间 2021-07-17 20:03
  • 提问者网友:你给我的爱
  • 2021-07-17 13:51

我要做的事情是:在HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SessionManager下新建一个DWORD的键值项,且命名为AutoChkTimeOut,将其键值设为1.

请问这个动作用vb该怎么写?

最佳答案
  • 五星知识达人网友:一把行者刀
  • 2021-07-17 14:37

操作注册表的代码比较多,这里不让发
'有关注册表问题
Private Declare Function RegEnumValue Lib "advapi32.dll" Alias "RegEnumValueA" (ByVal hKey As Long, ByVal dwIndex As Long, ByVal lpValueName As String, lpcbValueName As Long, lpReserved As Long, lpType As Long, lpData As Byte, lpcbData As Long) As Long
Private Declare Function RegEnumKeyEx Lib "advapi32.dll" Alias "RegEnumKeyExA" (ByVal hKey As Long, ByVal dwIndex As Long, ByVal lpName As String, lpcbName As Long, ByVal lpReserved As Long, ByVal lpClass As String, lpcbClass As Long, lpftLastWriteTime As FILETIME) As Long
Private 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
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Private 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 Long
Private 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
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, ByVal lpData As String, ByVal cbData As Long) As Long
Private Declare Function RegSetValueExA Lib "advapi32.dll" (ByVal hKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, ByRef lpData As Long, ByVal cbData As Long) As Long
'Private Declare Function RegSetValueExB Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal hkey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, ByRef
Private Declare Function RegDeleteKey Lib "advapi32.dll" Alias "RegDeleteKeyA" (ByVal hKey As Long, ByVal lpSubKey As String) As Long
Private Declare Function RegDeleteValue Lib "advapi32.dll" Alias "RegDeleteValueA" (ByVal hKey As Long, ByVal lpValueName As String) As Long
Public Declare Function RegSaveKey Lib "advapi32.dll" Alias "RegSaveKeyA" (ByVal hKey As Long, ByVal lpFile As String, ByVal lpSecurityAttributes As Long) As Long
Public Declare Function RegRestoreKey Lib "advapi32.dll" Alias "RegRestoreKeyA" (ByVal hKey As Long, ByVal lpFile As String, ByVal dwFlags As Long) As Long
Private Type FILETIME
dwLowDateTime As Long
dwHighDateTime As Long
End Type
Private Const ERROR_BADDB = 1009&
Private Const ERROR_BADKEY = 1010&
Private Const ERROR_CANTOPEN = 1011&
Private Const ERROR_CANTREAD = 1012&
Private Const ERROR_CANTWRITE = 1013&
Private Const ERROR_OUTOFMEMORY = 14&
Private Const ERROR_INVALID_PARAMETER = 87&
Private Const ERROR_ACCESS_DENIED = 5&
Private Const ERROR_NO_MORE_ITEMS = 259&
Private Const ERROR_MORE_DATA = 234&


Public Const REG_NONE = 0&
Public Const REG_SZ = 1&
Public Const REG_EXPAND_SZ = 2&
Public Const REG_BINARY = 3
Public Const REG_DWORD = 4&
Public Const REG_DWORD_LITTLE_ENDIAN = 4&
Public Const REG_DWORD_BIG_ENDIAN = 5&
Public Const REG_LINK = 6&
Public Const REG_MULTI_SZ = 7&
Public Const REG_RESOURCE_LIST = 8&
Public Const REG_FULL_RESOURCE_DESCRIPTOR = 9&
Public Const REG_RESOURCE_REQUIREMENTS_LIST = 10&


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 READ_CONTROL = &H20000
Public Const WRITE_DAC = &H40000
Public Const WRITE_OWNER = &H80000
Public Const SYNCHRONIZE = &H100000
Public Const STANDARD_RIGHTS_REQUIRED = &HF0000
Public Const STANDARD_RIGHTS_READ = READ_CONTROL
Public Const STANDARD_RIGHTS_WRITE = READ_CONTROL
Public Const STANDARD_RIGHTS_EXECUTE = READ_CONTROL
Public Const KEY_READ = STANDARD_RIGHTS_READ Or KEY_QUERY_VALUE Or KEY_ENUMERATE_SUB_KEYS Or KEY_NOTIFY
Public Const KEY_WRITE = STANDARD_RIGHTS_WRITE Or KEY_SET_VALUE Or KEY_CREATE_SUB_KEY
Public Const KEY_EXECUTE = KEY_READ


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


Dim lbuffer As Long, sbuffer As String, hKey As Long, ltype As Long, ldata As Long
Public Function GetReg(mainkey As Long, subkey As String, keyv As String, svalue) As Long
rtn = RegOpenKeyEx(mainkey, subkey, 0, KEY_READ, hKey)
If rtn <> ERROR_SUCCESS Then
getvalue = rtn
Exit Function
End If
rtn = RegQueryValueEx(hKey, keyv, 0, ltype, ByVal 0, lbuffer)
getvalue = rtn
Select Case ltype
Case REG_SZ
lbuffer = 255
sbuffer = Space(lbuffer)
rtn = RegQueryValueEx(hKey, keyv, 0, ltype, ByVal sbuffer, lbuffer)
getvalue = rtn
If rtn <> ERROR_SUCCESS Then
Exit Function
End If
svalue = Left(sbuffer, InStr(sbuffer, Chr(0)) - 1)
Case REG_EXPAND_SZ
sbuffer = Space(lbuffer)
rtn = RegQueryValueEx(hKey, keyv, 0, ltype, ByVal sbuffer, lbuffer)
getvalue = rtn
If rtn <> ERROR_SUCCESS Then
Exit Function
End If
svalue = Left(sbuffer, InStr(sbuffer, Chr(0)) - 1)
Case REG_DWORD
rtn = RegQueryValueEx(hKey, keyv, 0, ltype, ldata, lbuffer)
getvalue = rtn
If rtn <> ERROR_SUCCESS Then
Exit Function
End If
svalue = ldata
Case REG_BINARY
rtn = RegQueryValueEx(hKey, keyv, 0, ltype, ldata, lbuffer)
getvalue = rtn
If rtn <> ERROR_SUCCESS Then
Exit Function
End If
svalue = ldata
End Select
RegCloseKey hKey
End Function
Public Function SetReg(mainkey As Long, subkey As String, keyv As String, ltype, svalue, lbuffer As Long) As Long
Dim ss As SECURITY_ATTRIBUTES
ss.nLength = Len(ss)
ss.lpSecurityDescriptor = 0
ss.bInheritHandle = True
rtn = RegCreateKeyEx(mainkey, subkey, 0, "", 0, KEY_WRITE, ss, hKey, s)
setvalue = rtn
If rtn <> ERROR_SUCCESS Then
Exit Function
End If
Select Case ltype
Case REG_SZ
lbuffer = Len(svalue)
rtn = RegSetValueEx(hKey, keyv, 0, ltype, ByVal svalue, lbuffer)
setvalue = rtn
If rtn <> ERROR_SUCCESS Then
Exit Function
End If
Case REG_EXPAND_SZ
lbuffer = Len(svalue)
rtn = RegSetValueEx(hKey, keyv, 0, ltype, ByVal svalue, lbuffer)
setvalue = rtn
If rtn <> ERROR_SUCCESS Then
Exit Function
End If
Case REG_DWORD
lbuffer = 4
rtn = RegSetValueExA(hKey, keyv, 0, ltype, svalue, lbuffer)
setvalue = rtn
If rtn <> ERROR_SUCCESS Then
Exit Function
End If
Case REG_BINARY
rtn = RegSetValueExA(hKey, keyv, 0, ltype, svalue, lbuffer)
setvalue = rtn
If rtn <> ERROR_SUCCESS Then
Exit Function
End If
End Select
RegCloseKey hKey
End Function
Public Function openkey(mainkey As Long, subkey As String, ByVal ltype As Long, hKey As Long)
openkey = RegOpenKeyEx(mainkey, subkey, 0, ltype, hKey)
End Function
Public Function closekey(hKey As Long)
closekey = RegCloseKey(hKey)
End Function
Public Function DelReg(mainkey As Long, subkey As String, keyv As String)
rtn = RegOpenKeyEx(mainkey, subkey, 0, KEY_WRITE, hKey)
If rtn = 0 Then
rtn = RegDeleteValue(hKey, keyv)
rtn = RegCloseKey(hKey)
End If
End Function


我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯