Jump to content

Recommended Posts

Posted (edited)

I am trying to enumerate, and/or get a count of registry subkeys. I have never had this problem before, but I am unable to subkeys that are definitely there. I am starting my script so it is running elevated, but this makes no difference.

Here is the code that I am using to get the subkey count.

$rKey = _WinAPI_RegOpenKey($HKEY_LOCAL_MACHINE,"SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\Userdata\S-1-5-18\Products")
$arrayRKEY = _WinAPI_RegQueryInfoKey($rKey)
If IsArray($arrayRKEY) Then
                _ArrayDisplay($arrayRKEY)
Else
                MsgBox(0,"","No array" & @CR & "Error: " & @error & @CR & "Extended Error: " & @extended)
EndIf

The problem seems to be with the registry path, and If I change the path to this:

$rKey = _WinAPI_RegOpenKey($HKEY_LOCAL_MACHINE,"SOFTWARE\Microsoft\Windows\CurrentVersion")

It works fine. 

I don't get why I cannot get the information from the path I want.

Attached is a screenshot proving that I have numerous subkeys.

has anyone else seen this, or have a way to fix it? 

Thanks,

Jeff

post-54196-0-87591600-1412011306_thumb.j

Edited by jazzyjeff
Posted (edited)

Have you tried it with RegEnumKey instead?

Local $sSubKey = "", $i = 1
While 1
    $sSubKey = RegEnumKey("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\Userdata\S-1-5-18\Products", $i)
    If @error Then ExitLoop
    ConsoleWrite("SubKey #" & $i & " under HKLM\SOFTWARE: " & $sSubKey & @CRLF)
    $i += 1
WEnd
Edited by BrewManNH

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Posted

Thanks for your quick responses.

The built in Reg Functions were the first thing I tried, but I wasn't having success, so I started looking at the API functions.

BrewmanNH - Using the While loop with RegEnumKey was the first thing I tried, but I had no success. I just tried again with your code, but it still doesn't work.

Posted

I certainly could post all my code, but you're assuming there is something else wrong with the code , but that is not the case. This is the only piece of code that is failing. Here is all the code of a script I am using:

#include <WinAPIReg.au3>
#include <Array.au3>
Local $sHKLM_Inst = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer"
Local $sHKLM_UnInst64 = "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall"
Local $sHKLM_UnInst = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
$rKey = _WinAPI_RegOpenKey($HKEY_LOCAL_MACHINE, "SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\Userdata\S-1-5-18\Products")
$arrayRKEY = _WinAPI_RegQueryInfoKey($rKey)
If IsArray($arrayRKEY) Then
    _ArrayDisplay($arrayRKEY)
Else
    MsgBox(0, "", "No array" & @CR & "Error: " & @error & @CR & "Extended Error: " & @extended)
EndIf
_WinAPI_RegCloseKey($rKey)
Local $sSubKey = "", $i = 1
While @error <> 0
    $sSubKey = RegEnumKey("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\Userdata\S-1-5-18\Products", $i)
    MsgBox(0, "", "SubKey #" & $i & " under HKLM\SOFTWARE: " & $sSubKey & @CRLF)
    $i += 1
WEnd

I tried running a Reg Query from command line and this populates the subkeys fine... It's kind of a crappy way to get the information, but I may have to resort to exporting the keys from here. It seems like there is probably a configuration setting on my PC that isn't working. 

I am going to test this code on another box to see if that is also having problems reading back the registry keys to me.

Posted

Your While loop is wrong, @error will never happen so you're going to get stuck in it forever. Write it the way I wrote it and you'll be able to get out of the loop when you run out of keys to enumerate. BTW, my code as written works on my computer.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Posted

Exit. Thank you very much. The registry key I used was missing the 64... I am sure I didn't have to do that before. Oh well it's working now :-) Thanks very much

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...