Wrox Home  
Search P2P Archive for: Go

  Return to Index  

pro_vb thread: Registry API


Message #1 by Greg Partin <GPartin@c...> on Wed, 19 Sep 2001 18:11:21 -0400
Just by way of comparison, here is the comparable WSHOM code:

Dim WinShell         As IWshRuntimeLibrary.IWshShell_Class

   Set WinShell = New IWshRuntimeLibrary.IWshShell_Class
   Call WinShell.RegWrite("HKLM\SOFTWARE\TEST\", "Test Value", "REG_SZ")

See http://msdn.microsoft.com/scripting/windowshost/doc/wsmthregread.htm for
further details.

Cheers,

-Roy

-----Original Message-----
From: Marco Straforini [mailto:marco.straforini@c...]
Sent: Wednesday, September 19, 2001 6:29 PM
To: professional vb
Subject: [pro_vb] RE: Registry API


Greg,

my declarations are slightly different, but my code works.
Remember also to close the key by using RegCLoseKey()

BTW you should test the return value of RegCreateKeyEx. If
not zero, use the ErrorLookup application to find out the error
Almost always it is 87 'The parameter is incorrect.', that does
not say much because you have to find out which parameter
by yourself.

Have fun,
m.


--------------------------------------------------------------
Option Explicit

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, _
   ByVal lpSecurityAttributes As Long, _
   ByRef phkResult As Long, _
   ByRef lpdwDisposition As Long) As Long
Private Declare Function RegCloseKey Lib "advapi32.dll" _
   (ByVal hKey As Long) As Long

Private Const REG_SZ As Long = 1
Private Const REG_DWORD As Long = 4

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 ERROR_NONE = 0
Private Const ERROR_BADDB = 1
Private Const ERROR_BADKEY = 2
Private Const ERROR_CANTOPEN = 3
Private Const ERROR_CANTREAD = 4
Private Const ERROR_CANTWRITE = 5
Private Const ERROR_OUTOFMEMORY = 6
Private Const ERROR_ARENA_TRASHED = 7
Private Const ERROR_ACCESS_DENIED = 8
Private Const ERROR_INVALID_PARAMETERS = 87
Private Const ERROR_NO_MORE_ITEMS = 259

Private Const KEY_QUERY_VALUE = &H1
Private Const KEY_SET_VALUE = &H2
Private Const KEY_ALL_ACCESS = &H3F

Private Const REG_OPTION_NON_VOLATILE = 0

Private Sub Form_DblClick()
    Dim hRet As Long
    Dim lRetVal As Long
    Dim hKey As Long
    hRet = RegCreateKeyEx( _
                HKEY_LOCAL_MACHINE, "SOFTWARE\TEST", 0&, vbNullString, _
                REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, _
                0&, hKey, lRetVal)
    RegCloseKey hKey
End Sub



  Return to Index