Results 1 to 4 of 4

Thread: Registry problems!

  1. #1

    Thread Starter
    Hyperactive Member Petergotchi's Avatar
    Join Date
    Jan 2002
    Location
    Dendermonde - Belgium
    Posts
    267

    Registry problems!

    Public Sub SetupScancodeMap()
    Dim bArray(1 To 48) As Byte

    On Error Resume Next
    If g_bDebugMode = True Then Exit Sub
    '
    ' Setup the keyboard scancode mapping to disable the Windows keys
    ' and Context menu keys
    '
    bArray(1) = &H0
    bArray(2) = &H0
    bArray(3) = &H0
    bArray(4) = &H0

    bArray(5) = &H0
    bArray(6) = &H0
    bArray(7) = &H0
    bArray(8) = &H0
    '
    ' Number of keys
    '
    bArray(9) = &H6
    bArray(10) = &H0
    bArray(11) = &H0
    bArray(12) = &H0
    '
    ' Windows key
    '
    bArray(13) = &H0
    bArray(14) = &H0
    bArray(15) = &H5B
    bArray(16) = &HE0
    '
    ' Windows key
    '
    bArray(17) = &H0
    bArray(18) = &H0
    bArray(19) = &H5C
    bArray(20) = &HE0
    '
    ' Windows menu key
    '
    bArray(21) = &H0
    bArray(22) = &H0
    bArray(23) = &H5D
    bArray(24) = &HE0
    '
    ' F10 key
    '
    bArray(25) = &H0
    bArray(26) = &H0
    bArray(27) = &H44
    bArray(28) = &H0
    '
    ' Left Ctrl-key
    '
    bArray(29) = &H0
    bArray(30) = &H0
    bArray(31) = &H1D
    bArray(32) = &H0
    '
    ' Left Alt-key
    '
    bArray(33) = &H0
    bArray(34) = &H0
    bArray(35) = &H38
    bArray(36) = &H0
    '
    ' Right Ctrl-key
    '
    bArray(37) = &H0
    bArray(38) = &H0
    bArray(39) = &H1D
    bArray(40) = &HE0
    '
    ' Right Alt-key
    '
    bArray(41) = &H0
    bArray(42) = &H0
    bArray(43) = &H38
    bArray(44) = &HE0
    '
    ' Null terminator
    '
    bArray(45) = &H0
    bArray(46) = &H0
    bArray(47) = &H0
    bArray(48) = &H0
    '
    ' Set the new registry value, does not take effect until the next reboot.
    ' You can use my registry module or your own routine to write the value to the registry.
    '
    Reg_SetKeyValue HKEY_LOCAL_MACHINE, "SYSTEM\CurrentControlSet\Control\KeyboardLayout", "Scancode Map", bArray, REG_BINARY
    End Sub


    This is the code I got. It's a code to lock out certain keyboardkeys for win2k and XP. But the last sentence is quite a pain in the ass. It needs a module which I don't have! Is there another way to write it to the registry? Is there someone with a little more experience with this sort of stuff than me and willing to rewrite this? Pls? Thx in advance!
    Kind Regards,

    Pieter

    PS: If you found someone's answer helpful, please be so kind to rate that person.
    Thanks.

  2. #2
    Addicted Member
    Join Date
    Jul 2001
    Posts
    133
    "But the last sentence is quite a pain in the ass. It needs a module which I don't have! Is there another way to write it to the registry?"

    Why do you need a module for it? If you do, why can you not have a module?

    Why are you not calling the standard Windows API functions to do this. If you use these, you don't necessarily need a module.

  3. #3

    Thread Starter
    Hyperactive Member Petergotchi's Avatar
    Join Date
    Jan 2002
    Location
    Dendermonde - Belgium
    Posts
    267

    Because I'm no good...

    in programming!
    I don't know a lot about API's and registry stuff. Can you blame me? If you think it's so easy to do, why don't you make this thing work? Can you help me?
    Kind Regards,

    Pieter

    PS: If you found someone's answer helpful, please be so kind to rate that person.
    Thanks.

  4. #4
    Si_the_geek
    Guest
    Add this to your module/form:
    (NB: I don't have the declaration for "reg_binary" here, try reg_DWORD instead, or search the 'net for it).

    VB Code:
    1. Public Enum Reg_HKey_Area         'Constants for specifying areas
    2.   HKEY_CLASSES_ROOT = &H80000000
    3.   HKEY_CURRENT_USER = &H80000001
    4.   HKEY_LOCAL_MACHINE = &H80000002
    5.   HKEY_USERS = &H80000003
    6. End Enum
    7.  
    8. Const ERROR_NONE = 0   'Function results (if specified in the function)
    9. Const ERROR_BADDB = 1
    10. Const ERROR_BADKEY = 2
    11. Const ERROR_CANTOPEN = 3
    12. Const ERROR_CANTREAD = 4
    13. Const ERROR_CANTWRITE = 5
    14. Const ERROR_OUTOFMEMORY = 6
    15. Const ERROR_ARENA_TRASHED = 7
    16. Const ERROR_ACCESS_DENIED = 8
    17. Const ERROR_INVALID_PARAMETERS = 87
    18. Const ERROR_NO_MORE_ITEMS = 259
    19. Const ERROR_INSUFFICIENT_BUFFER = 122
    20. Const ERROR_KEY_DELETED = 1018
    21. Const ERROR_REGISTRY_CORRUPT = 1015
    22.  
    23. Public Enum Reg_Data_Type         'Constants for specifying data types
    24.   Reg_String = &O1
    25.   Reg_Dword = &O4
    26. End Enum
    27.  
    28. Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
    29. Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias "RegOpenKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, _
    30.    ByVal ulOptions As Long, ByVal samDesired As Long, phkResult As Long) As Long
    31. Declare Function RegSetValueExString Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, _
    32.    ByVal Reserved As Long, ByVal dwType As Long, ByVal lpValue As String, ByVal cbData As Long) As Long
    33. Declare Function RegSetValueExLong Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, _
    34.    ByVal Reserved As Long, ByVal dwType As Long, lpValue As Long, ByVal cbData As Long) As Long
    35.  
    36.  
    37.  
    38. Function Reg_SetKeyValue(KeyArea As Reg_HKey_Area, sKeyName As String, sValueName As String, vValue As Variant, Optional lValueType As Reg_Data_Type)
    39. 'Sets a specified value in the registry (may or may not exist already).
    40.  
    41. 'NB:  This will only work if the KEY exists.  To ensure it does
    42. '     you can simply call Reg_CreateNewKey (which creates it if
    43. '     necessary) or Reg_CheckKeyExists.
    44.  
    45. 'Returns codes as listed in DECLARATIONS (ie: 0=error_none = no error)
    46. Dim lRetVal As Long, hKey As Long
    47.  
    48.             'try to detect type!
    49.     If lValueType <> Reg_String And lValueType <> Reg_Dword Then
    50.       lValueType = Reg_String
    51.       If (IsNumeric(vValue)) Then
    52.         If CInt(vValue) = vValue Then lValueType = Reg_Dword
    53.       End If
    54.     End If
    55.                                     'open the specified key
    56.     lRetVal = RegOpenKeyEx(KeyArea, sKeyName, 0, KEY_ALL_ACCESS, hKey)
    57.     If lRetVal <> ERROR_NONE Then Reg_SetKeyValue = lRetVal: Exit Function
    58.    
    59.     Select Case lValueType          'set the value
    60.     Case Reg_String:   Reg_SetKeyValue = RegSetValueExString(hKey, sValueName, 0&, Reg_String, CStr(vValue & Chr$(0)), CLng(Len(vValue) + 1))
    61.     Case Reg_Dword:    Reg_SetKeyValue = RegSetValueExLong(hKey, sValueName, 0&, Reg_Dword, CLng(vValue), 4)
    62.     End Select
    63.  
    64.     RegCloseKey (hKey)              'close the key
    65.  
    66. End Function

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width