Solved

Reading Local Users Registry & Closing Registry Afterwards

Posted on 2004-09-06
1
493 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 86

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

734 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