Solved

Reading Local Users Registry & Closing Registry Afterwards

Posted on 2004-09-06
1
492 Views
Last Modified: 2008-01-09
I want to read settings out of the other local users registry's on the local PC. I dont know if this is the best way but its the only way i've found so far and i cant seem to get regloadkey to work:

Firstly I run a shell command:
REG load HKLM\TempData "F:\Documents and Settings\Test\ntuser.dat"

This loads the user hive into a tempory key called TempData under HKLM

I can now read all the settings i want from it.

when I am finished with that users hive, i need to unload it to load another the shell command is:
reg unload HKLM\TempData

when I run this is returns:
Error:  Access is denied.

and I can not unload the hive until i quit VB6.

Perhaps I am not closing my keys properly? or somthing else?

The code i am using for reading the registry keys is:

Public Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, ByVal lpData As String, lpcbData As Long) As Long
Public Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Public Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Public Const REG_SZ = 1
Public Const LOCALMACHINE = &H80000002

nBufferData = Space(256)
RegOpenKey LOCALMACHINE, MainKey, nBufferKey
RegOpenKey nBufferKey, SubKey, nBufferSubKey
RegQueryValueEx nBufferSubKey, RegItem, 0, REG_SZ, nBufferData, Len(nBufferData)
RegCloseKey LOCALMACHINE


Any Ideas on any of this anyone?
0
Comment
Question by:xizor
1 Comment
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 250 total points
ID: 11989894
You are not closing the keys correctly...

This:

    RegCloseKey LOCALMACHINE

should be:

    RegCloseKey nBufferKey
    RegCloseKey nBufferSubKey

Regards,

Idle_Mind
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

713 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question