none
WMI Enumkey does not return all subkeys RRS feed

  • Question

  • I am using WMI in a .hta HTML application to pull info from the registry. I noticed that some keys are not being returned in the array when I run it on Windows 10

    The image below shows an example - the key inside the red box

    (the .hta output is on the left and regedit is on the right.

    Any suggestions?  Is it an issue with registry key permissions maybe?

    Thanks for any help...

    <head>
    <title>Shell commands</title>
    <HTA:APPLICATION
         id="oHTA"
         APPLICATIONNAME="Shell commands"
         SCROLL="yes"
         SINGLEINSTANCE="yes"
         SysMenu="yes"
         ShowInTaskbar="yes"
         WindowState="normal"
         VERSION="1.0"
    >
    <STYLE>
      body {font-family:Verdana, Tahoma; font-size:10pt; color:blue;}
    </STYLE>

    <script language="VBScript">
     option explicit

     Const HKEY_LOCAL_MACHINE = &H80000002
     const fldrx64 = "SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FolderDescriptions"
     const fldrx86 = "SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\explorer\FolderDescriptions"

      Dim regkey
      Dim strComputer, oReg, arrSubKeys, subkey
      Dim fldrname, rc, msg

      strComputer = "."

      regkey = fldrx64

      Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
        strComputer & "\root\default:StdRegProv")

      msg = ""
      oReg.EnumKey HKEY_LOCAL_MACHINE, regkey, arrSubKeys
      for each subkey in arrSubkeys
          rc = oReg.GetStringValue(HKEY_LOCAL_MACHINE,  regkey & "\" & subkey , "Name", fldrname)
          if rc = 0 then
            msg = msg & subkey & " : "& fldrname & "<BR>"
          end if
      next

    Sub Window_Onload
      info.innerHTML = msg
    End Sub</script>

    <body>
    <div id='info'></div>
    </body>


    Tuesday, April 10, 2018 6:57 PM

Answers

  • Two registries with some things "reflected" from  one to the other.  Look up the registry documentation on MSDN and read how the registry works and how to access it in various ways.

    Note that the 64 bit registry can see the 32 bit registry but the 32 bit registry cannot see the 64 bit registry.  If you run as 32 bit only the 32 bit registry values are visible.


    \_(ツ)_/

    • Marked as answer by MicroZapman Tuesday, April 10, 2018 8:14 PM
    Tuesday, April 10, 2018 8:01 PM

All replies

  • I figured it out but I'm not sure why it behaves as it does.

    I the .hta file is run using the Windows\SysWow64\mshta.exe, the key is skipped, but if
    it is run using Windows\System32\mshta.exe, the particular key IS returned in the array.

    Tuesday, April 10, 2018 7:08 PM
  • I cannot reproduce your issue.  It is possible that some keys may be protected.

    I run your code and that key displays for me.

    Try this to check for errors:

    <html>
    
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
    <title>My HTML Application</title>
    <script language="vbscript">
    <!-- Insert code, subroutines, and functions here -->
    
    </script>
    <hta:application
    	applicationname="MyHTA"	
    	border="dialog"
    	borderstyle="normal"
    	caption="My HTML Application"
    	contextmenu="no"
    	icon="myicon.ico"
    	maximizebutton="no"
    	minimizebutton="yes"
    	navigable="no"
    	scroll="no"
    	selection="no"
    	showintaskbar="yes"
    	singleinstance="yes"
    	sysmenu="yes"
    	version="1.0"
    	windowstate="normal"
    >
    <script language="VBScript">
    
    	Const HKEY_LOCAL_MACHINE = &H80000002
    	const fldrx64 = "SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FolderDescriptions"
    	const fldrx86 = "SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\explorer\FolderDescriptions"
    	
    	Dim regkey
    	 Dim strComputer, oReg, arrSubKeys, subkey
    	 Dim fldrname, rc, msg
    	
    	strComputer = "."
    	
    	regkey = fldrx64
    	
    	Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")
    	
    	msg = "" 
    	oReg.EnumKey HKEY_LOCAL_MACHINE, regkey, arrSubKeys
    	for each subkey in arrSubkeys
    		rc = oReg.GetStringValue(HKEY_LOCAL_MACHINE,  regkey & "\" & subkey , "Name", fldrname)
    		if rc = 0 Then
    			msg = msg & subkey & " : "& fldrname & "<BR>"
    		Else
    			MsgBox "key error " & rc
    		end If
    	next
    
    	Sub Window_Onload
    	   document.body.innerHTML = msg
    	End Sub
     
    </script>
    </head>
    <body>
    </body>
    </html>


    \_(ツ)_/


    • Edited by jrv Tuesday, April 10, 2018 7:27 PM
    Tuesday, April 10, 2018 7:22 PM
  • Yes.  The 32 bit and 64 bit registries have different views.  Some items may not be in both views.


    \_(ツ)_/

    Tuesday, April 10, 2018 7:26 PM
  • And yes.  That key is only in the 64 bit registry.


    \_(ツ)_/

    Tuesday, April 10, 2018 7:28 PM
  • Thanks, I figured it out by check both the 32-bit and 64-bit of regedit

    I did not realize that there was a distinction. 

    Are there two different registries or just entries that are only that can only be seen in each editor?

    Tuesday, April 10, 2018 7:52 PM
  • Two registries with some things "reflected" from  one to the other.  Look up the registry documentation on MSDN and read how the registry works and how to access it in various ways.

    Note that the 64 bit registry can see the 32 bit registry but the 32 bit registry cannot see the 64 bit registry.  If you run as 32 bit only the 32 bit registry values are visible.


    \_(ツ)_/

    • Marked as answer by MicroZapman Tuesday, April 10, 2018 8:14 PM
    Tuesday, April 10, 2018 8:01 PM
  • Thanks - I found more info as you suggested

    32-bit and 64-bit Application Data in the Registry

    Tuesday, April 10, 2018 8:16 PM