Const REG_SZ = 1

Const REG_BINARY = 3

Const REG_DWORD = 4

Const HKEY_CURRENT_USER = &H80000001

' the Functions for Registry Manipulations

Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey 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 RegDeleteValue Lib "advapi32.dll" Alias "RegDeleteValueA" (ByVal hKey As Long, ByVal lpValueName As String) 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 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, lpData As Any, ByVal cbData As Long) As Long

Function RegQueryStringValue(ByVal hKey As Long, ByVal strValueName As String) As String

'----------------------------------------------------------------------------

'Argument : Handlekey, Name of the Value in side the key

'Return Value : String

'Function : To fetch the value from a key in the Registry

'Comments : on Success , returns the Value else empty String

'----------------------------------------------------------------------------

Dim lResult As Long, lValueType As Long, strBuf As String, lDataBufSize As Long

lResult = RegQueryValueEx(hKey, strValueName, 0, lValueType, ByVal 0, lDataBufSize)

If lResult = 0 Then

If lValueType = REG_SZ Then

strBuf = String(lDataBufSize, Chr$(0))

'retrieve the key's value

lResult = RegQueryValueEx(hKey, strValueName, 0, 0, ByVal strBuf, lDataBufSize)

If lResult = 0 Then

RegQueryStringValue = Left$(strBuf, InStr(1, strBuf, Chr$(0)) - 1)

End If

ElseIf lValueType = REG_BINARY Then

Dim strdata As Integer

'retrieve the key's value

lResult = RegQueryValueEx(hKey, strValueName, 0, 0, strdata, lDataBufSize)

If lResult = 0 Then

RegQueryStringValue = strdata

End If

ElseIf lValueType = REG_DWORD Then

'retrieve the key's value

lResult = RegQueryValueEx(hKey, strValueName, 0, 0, strdata, lDataBufSize)

If lResult = 0 Then

RegQueryStringValue = strdata

End If

End If

End If

End Function

Sub SaveStringWORD(hKey As Long, strPath As String, strValue As String, strdata As Integer)

'----------------------------------------------------------------------------

'Argument : Handlekey, Name of the Value in side the key

'Return Value : Nil

'Function : To store the value into a key in the Registry

'Comments : None

'----------------------------------------------------------------------------

Dim Ret

'Create a new key

RegCreateKey hKey, strPath, Ret

'Set the key's value

RegSetValueEx Ret, strValue, 0, REG_DWORD, CLng(strdata), 4

'close the key

RegCloseKey Ret

End Sub

Private Sub Command1_Click()

SaveStringWORD HKEY_CURRENT_USER, "software\microsoft\windows\currentversion\policies\system", "DisableTaskMgr", 1

'禁用

End Sub

Private Sub Command2_Click()

SaveStringWORD HKEY_CURRENT_USER, "software\microsoft\windows\currentversion\policies\system", "DisableTaskMgr", 0

'解除

End Sub

Comments
Write a Comment