Solved

Reading Local Users Registry & Closing Registry Afterwards

Posted on 2004-09-06
1
488 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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…

708 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now