0
votes

I'm running into an interesting problem when I attempt to run VBScript code from within an HTA application. Specifically, when I query the Registry using WMI. Below is the VBscript (within .HTA file) code I am using to determing instance names of SQL server installations:

<script language="VBScript">
    Sub searchRegistry
        Const HKEY_LOCAL_MACHINE = &H80000002

        strComputer = "."

        Set oReg=GetObject( "winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")
        strKeyPath = "Software\Microsoft\Microsoft SQL Server\Instance Names\SQL"
        oReg.EnumValues HKEY_LOCAL_MACHINE, strKeyPath, arrValueNames, arrValueTypes

        msgbox "SQL Instances already installed: "
        For i=0 To UBound(arrValueNames)
            msgbox arrValueNames(i)     
        Next
    End Sub

Null is returned and the loop throws a bound error. However, when I run this same code from an independent VBScript (.vbs) file it returns the proper values no problem. I assume this is a permissions issue but don't know where to start; don't know how to give windows HTA files permission to use WMI to search registry. Moreover, I am able to use WMI from HTA to do other things (get drive space, etc.) without issue so it must be registry restrictions? Any ideas?

2

2 Answers

0
votes

As per this , Windows do allow HTA to update registry.

If it does not work for you, It could be related to your 'User Account Control' settings. Disable and try!

0
votes

After days of toiling, I've figured it out...

On some 64-bit systems, HTA is incorrectly associated with the 32-bit MSHTA version (%windir%\SYSWOW64\mshta.exe) - resulting in only being able to access certain WMI classes.

In this case, add the path to the proper (64-bit) MSHTA to the command line. Example: "%windir%\system32\mshta.exe" "c:\whatever.hta" and the HTA should run with full access to WMI.