Solved

Reading Local Users Registry & Closing Registry Afterwards

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

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…
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…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

777 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