vbscript "activex component can't create object: 'ADODB.Connection'" RRS feed

  • Question

  • I have an HTA file that is basically a compilation of scripts that I use, and share with others.  I've been developing it since 2011.  One of the earliest scripts added was searching AD for servers and returning what OU they were found in.  So to say the least, this has been a tried and true script.  Now all of a sudden last week, I started getting an error saying the script was causing the web browser to run slowly.  I rem'd out On Error Resume Next and found the offending line is 'Set objConnection = CreateObject("ADODB.Connection").  The error statement is "activex component can't create object: 'ADODB.Connection'".  I've checked with another person who uses my toolbox and they said it works just fine for them.  So luckily it's only affecting me right now, but who knows how long that will last.  My company locks down our computers so there's not a lot I can do to make changes to my computer.  I'll try anything you guys suggest, I just might not have rights to do so.

    • Edited by Carl_S_S Monday, March 4, 2019 2:26 PM
    • Moved by Bill_Stewart Wednesday, September 4, 2019 6:46 PM This is not "design solution for me" forum
    Monday, March 4, 2019 2:24 PM

All replies

  • Is this file on your machine and do you have read access? (I'm running Win10 Home.)

     C:\Program Files\Common Files\System\ado\msado15.dll

    Open an administrator command prompt and run:

    regsvr32 "C:\Program Files\Common Files\System\ado\msado15.dll"

    If they did not give you admin access, then you will need to contact your support team for help. 

    Monday, March 4, 2019 2:43 PM
  • So I suppose I should have stated the OS, it's WIndows 7 Enterprise.  I do have a way to get admin rights to the command prompt and ran the line as you stated but no change.  I figured I didn't have to, but rebooted anyway, no change.
    Monday, March 4, 2019 3:46 PM
  • Please post the code you have and the exact error.

    All systems since Windows 2000 have ADO installed.

    Admin rights are not required


    Monday, March 4, 2019 3:51 PM
  • The exact error was notated in the original post, "activex component can't create object: 'ADODB.Connection'".

    Here's the entire script, company name and domain have been changed to protect the innocent.  The error occurs on line 21.

    Sub btnOU_OnClick
    Dim f, fx, objFile, strServerName, strComputerName, tname, TempFile, results, ts, retString, objConnection, objCommand, RS, tempstring
    Dim strSeparator, strDomain, arrValue, xLen, temp,  ReverseOU, strOUOnly, strNiC, strCN, tx, i, fxo, retName, arrReturn, strDN
    On Error Resume Next

    Set f = fso.OpenTextFile(strInputFile, ForReading, True)
    Set fx = fso.CreateTextFile(strToolboxFolder & "OutputFiles\results.OU.csv", ForWriting, True)

    if  Err.Number <> 0  then
        MsgBox "Ran into an error.  Make sure that the results.OU.csv Excel file is closed before running again."
        Exit Sub
    End If

    fx.writeline "sep=,"

    wshShell.Run "notepad " & strInputFile, 1, True

    '==============Make Connection to Active Directory==============
    Set objConnection = CreateObject("ADODB.Connection")
    Set objCommand = CreateObject("ADODB.Command")
    objConnection.Provider = "ADsDSOObject"
    objConnection.Open "Active Directory Provider"
    Set objCommand.ActiveConnection = objConnection
    '===============End Make Connection=============================

    fx.writeline "Server Name, OU Path, Distinguished Name"
    Do While f.AtEndOfLine <> True
        strServerName = f.Readline
        retName = Trim(strServerName)
        arrReturn = Split(retName,".")
        strComputerName = arrReturn(0)

        objCommand.CommandText = "<GC://DC=dom,DC=FakeCompanyName,DC=com>;(CN=" & strComputerName & ");adspath"
        Set RS = objCommand.Execute

        tname = fso.GetTempName
        TempFile = strToolboxFolder & tname
        Set tx = fso.OpenTextFile(TempFile, ForWriting, True)
        While not RS.EOF
            tx.writeline RS.fields(0)

        set results = fso.GetFile(TempFile)
        set tempstring = results.OpenAsTextStream(ForReading)
        retString = tempstring.ReadLine
        if  Err.Number <> 0  then
            strNiC ="server not in domain"
        End If
        strDN = Replace(retString, "GC://CN=" & strComputerName & ",","")
        strCN = Replace(retString, "GC://CN=","")
        strSeparator = Replace(strCN, ",OU=","\")
        strDomain = Replace(strSeparator, ",DC=dom,DC=FakeCompanyName,DC=com","\dom")

        arrValue = Split(strDomain, "\")
        xLen = UBound(arrValue) + 1

        For i = 0 To ((xLen - 1) / 2)
            temp = arrValue(i)
            arrValue(i) = arrValue(xLen - i - 1)
            arrValue(xLen - i - 1) = temp

        ReverseOU = Join(arrValue, "\")
        strOUOnly = Replace(ReverseOU, "\" & strComputerName,"",1,-1,1)
        fx.writeline strComputerName & "," & strOUOnly & strNiC & "," & """" & strDN & """"
        strDN = ""
        strNiC = ""
        retString = ""
    wshShell.Run "excel.exe " & strToolboxFolder & "OutputFiles\results.OU.csv", 1, False

    End Sub

    • Edited by Carl_S_S Monday, March 4, 2019 6:02 PM
    Monday, March 4, 2019 4:15 PM
  • Create a c:\temp\test.vbs with notepad that contains these lines:

    Set objConnection = CreateObject("ADODB.Connection")
    Set objConnection = CreateObject("ADODB.Recordset")
    Set objConnection = CreateObject("ADOX.Catalog")
    Set objConnection = CreateObject("ADOMD.Catalog")
    wscript.echo "Done."

    Since your code used to work, and "should" work, my thought is to try to narrow down where the problem lies. IE; is it every object exposed by msado15.dll and does the problem apply to every ado dll.

    Open a command prompt and run "c:\windows\system32\cscript.exe c:\temp\test.vbs"

    If your system is x64 also run "c:\windows\syswow64\cscript.exe c:\temp\test.vbs" 

    Monday, March 4, 2019 6:57 PM
  • Place the following line in a single VBS file and test.

    Set objConnection = CreateObject("ADODB.Connection")

    If it falis then you have system issues and need to either reregister the ADO components or repair the system.


    Monday, March 4, 2019 6:58 PM
  • Thanks Jrv and Moto.  The suggestion worked with no issue.  So then I exported the sub to this test.vbs file and it works as it should.  So there's something I need to find somewhere else in the .hta file.  This is just super weird though since I'm the only person experiencing it and I tried several backups before starting this thread.  Each had the same issue.  Well thanks for helping me get started here.  I'll leave the thread open till I figure out the issue and then post what it was so that it might help someone else one day :) .
    • Edited by Carl_S_S Tuesday, March 5, 2019 6:53 PM
    Tuesday, March 5, 2019 6:51 PM
  • Check your IE settings.

    And try both the 32 and 64 bits executables from an admin command prompt.

    c:\windows\system32\mshta.exe your.hta

    c:\windows\syswow64\mshta.exe your.hta

    • Edited by MotoX80 Tuesday, March 5, 2019 7:40 PM
    Tuesday, March 5, 2019 7:21 PM
  • Ugh.  This is not good.  It ran fine with the mshta run as admin.  After that test, I renamed test.vbs to test.hta and copied just the HTML code to it.  Had the exact same error as the original HTA file.  Unfortunately the company locks down those IE settings so I can't modify them.  I can't even look at them.  I guess my work around will be to have the HTA call an external .vbs file to run that script and a couple others that are having the exact same issue.  I guess it's possible that I'm just one of the first people that they've pushed this setting to and the other people that the script works for just haven't received the update yet.

    Tuesday, March 5, 2019 8:49 PM
  • Just place the VBS code in an event in the HTA.  HTAs can easily execute VBS with some exceptions.  You cannot output from an HTA.


    Tuesday, March 5, 2019 9:07 PM
  • Save this as test.hta

    		<title>Test HTA</title>
    		<script language="vbscript">
    option explicit
    Sub btnOK_OnClick
    	Dim oConn
    	set oConn = CreateObject("ADODB.Connection")
    	set oConn = nothing
    	oStatus.innerHtml = "It worked at " & now
    End Sub
    		<table align="center" ID="Table1">
    						<input id="btnOK" type="button" value="Test" name="btnOK"> 
    						<div id="oStatus"></div>

    Tuesday, March 5, 2019 9:30 PM
  • Same issue Moto.
    Wednesday, March 6, 2019 2:16 PM
  • Does the VBS work correctly?

    Try this to get the full error.  You don't need complex HTML just this:

    <title>Test HTA</title>
    <script language="vbscript">
    Sub btnOK_OnClick
    	On Error Resume Next
    	Dim oConn
    	set oConn = CreateObject("ADODB.Connection")
    	If Err Then msgbox Err.Number & "   " & Err.Description 
    	set oConn = nothing
    	msgbox "It worked at " & now
    End Sub
    <input id="btnOK" type="button" value="Test" name="btnOK"> 

    Don't use Notepad++ or other editor.  Use notepad and be sure to save the file as ANSI.  Use a new filename to avoid conflicts.  I think you will see why this is not working in an HTA when it works in a VBS.


    Wednesday, March 6, 2019 2:43 PM
  • Same issue Moto.

    Just for fun.... create a new user on your machine, add it to the administrators group. Log on with that account and run the test.hta. 
    Wednesday, March 6, 2019 3:08 PM
  • Same issue Moto.

    Just for fun.... create a new user on your machine, add it to the administrators group. Log on with that account and run the test.hta. 

    I can almost absolutely guarantee the issue is with the file.  I can recreate it very easily.

    The issue only affects HTA and HTML files running VBScripts that use ActiveX objects.


    Wednesday, March 6, 2019 3:12 PM
  •   I can recreate it very easily.

    It's working fine for me on Win10 Home. 

    Wednesday, March 6, 2019 3:38 PM
  • You miss my point.  Of course your test works.  You built it in notepad.  The OP likely built it in another editor which creates the wrong kind of file which is why I specifically asked the file to be created in notepad as ANSI. 

    HTA does not work correctly with non-ANSI files and notepad++ adds odd characters to files that can break HTA files.


    Wednesday, March 6, 2019 3:52 PM
  • No, I'm using notepad++. And I hear what you're saying, but I cannot get the HTA to fail.

    I used regular notepad and did a 'save as' for each encoding type. I see the difference in file sizes. But they all work for me. I coped these 4 hta's to a test VM I have.  Win 10 Pro. They all work there too.

    Wednesday, March 6, 2019 6:15 PM
  •  I guess it's possible that I'm just one of the first people that they've pushed this setting to and the other people that the script works for just haven't received the update yet.

    What setting are you referring to? IE settings? Are other users able to view their IE settings? Have you asked your desktop support team if they have made any group policy security changes recently?

    Try this version of the test hta and see if you can create any objects.

    		<title>Test HTA</title>
    		<script language="vbscript">
    option explicit
    Sub btnOK_OnClick
    	oStatus.innerHtml = "Testing at " & now
    	tester "ADODB.Connection"
    	tester "ADODB.Recordset"
    	tester "Scripting.FileSystemObject"
    	tester "zzzzzzzzzz"
    End Sub
    function Tester(obj)
    	Dim oConn
    	on error resume next
    	set oConn = CreateObject(obj)
    	if err then
    		oStatus.innerHtml = oStatus.innerHtml & "<br>Error creating " & obj & "  " & err.number & " - " & err.description
    		oStatus.innerHtml = oStatus.innerHtml & "<br>Success! " & obj
    	end if
    	set oConn = nothing	
    end function
    		<table align="center" ID="Table1">
    						<input id="btnOK" type="button" value="Test" name="btnOK"> 
    						<div id="oStatus"></div>

    Wednesday, March 6, 2019 6:20 PM
  • No, I'm using notepad++. And I hear what you're saying, but I cannot get the HTA to fail.

    I used regular notepad and did a 'save as' for each encoding type. I see the difference in file sizes. But they all work for me. I coped these 4 hta's to a test VM I have.  Win 10 Pro. They all work there too.

    That is because your notepad++ is set up correctly. That is not always the case.


    Wednesday, March 6, 2019 7:06 PM
  • Stop screwing around and be sure the file is saved as ANSI.


    Wednesday, March 6, 2019 7:07 PM
  • That is because your notepad++ is set up correctly.

    Stop screwing around and be sure the file is saved as ANSI.

    I am not using notepad++ anymore. (re: "I used regular notepad and did a 'save as' for each encoding type.")

    I am using good old builtin notepad. I can save the file with any of these encodings and it works just fine.

    You said that you could recreate it very easily.  I'm sorry but I cannot replicate that. I would think that if mshta.exe does not like a file's encoding then it won't display at all. The fact that it crashes on a createobject call says that mshta can interpret it well enough to make that call. 

    If you feel that my screwing around is wasting your time, then feel free to ignore me. Anyway, this part of the discussion can stop because it's not related to the original question.   

    Wednesday, March 6, 2019 7:32 PM
  • I use an old version of EditPlus (ver 3.30).  It saves it in HTML, HTM, ASP, SAS, ASPX, ASAX, SHTML, STM and HTA formats.  This is the exact same tool, exact same version that I used when I started this toolbox back in 2011.  So from a development standpoint nothing has changed.  However, there could be changes the company pushed out to my computer.  The encoding is set to ANSI.  Opening it in Notepad and saving it made no difference.

    As to your question about what settings.  Yes, IE settings.  No one has rights to look at their IE settings, administration has them locked down by group policy. 

    • Edited by Carl_S_S Wednesday, March 6, 2019 9:12 PM
    Wednesday, March 6, 2019 9:06 PM
  • Just for fun.... create a new user on your machine, add it to the administrators group. Log on with that account and run the test.hta. 

    Don't have rights to create an account.  Don't have admin rights.  I can get admin rights to the command prompt.  Running the toolbox using the command prompt in admin mode allowed everything to work as it should.
    Wednesday, March 6, 2019 9:18 PM
  • Running the toolbox using the command prompt in admin mode allowed everything to work as it should.

    Then there is nothing that we can do to help you. 
    • Marked as answer by Carl_S_S Thursday, March 7, 2019 3:36 PM
    • Unmarked as answer by Carl_S_S Friday, March 15, 2019 3:50 PM
    Thursday, March 7, 2019 1:08 AM
  • yeah, I realized that back when you had me run the toolbox from the command prompt with admin rights and run a simple hta.  It ran with admin, wouldn't run a simple hta as me, so it just won't work as is.  I think they pushed some update to my computer that borked it.  It seems to be running slower than normal too.  I'll have to update the hta to launch an external .vbs file for these scripts.  I have 4 that do AD lookups using CreateObject("ADODB.Connection").  And of course, all 4 have the same issue.

    Thanks for your help, Moto and Jrv

    Thursday, March 7, 2019 3:36 PM
  • Out of curiosity, is it only failing on ADODB.Connection? Is the HTA able to create Scripting.FileSystemObject?
    Thursday, March 7, 2019 3:48 PM
  • Yes, the CreateObject("ADODB.Connection") is the only thing that fails.  I use it for telling me what OU a server is in, what OUs an ID or Group are used in, and the contents of those groups.  All failing.  The HTA works for returning the contents of an OU, which just uses GetObject("LDAP://" strOU), ping a list of servers, a server name generator and quite a few other things.

    Now I have another question.  I created the return OU script as a standalone .vbs file and it works as expected when I double click on it, Opens Notepad for a list, writes header info to Excel Output file, then searches AD for each, writes data to Excel Output file then opens Excel showing what it found.   I modified the HTA to run it using the following.

    Set WshShell = CreateObject("Wscript.Shell")
    wshShell.Run strToolboxFolder & "\ReturnOU.vbs"

    When run this way, Notepad opens but then nothing else happens.  When I open Task Manager, I see wscript running, using about 25% cpu.  This continues until I do an End Process on it.  Nothing gets written to the Excel file except the header info before searching AD.

    The exact code is listed near the top of this thread.  Only changes were that it's no longer a sub and I changed the line "Exit Sub" to wscript.quit.

    I tried changing wshShell.Run strToolboxFolder & "\ReturnOU.vbs" to "cmd /c "strToolboxFolder & "\ReturnOU.vbs", thinking that the HTA is just running a command window and then the script execution would be completely external, but no difference.

    Any ideas?

    Friday, March 15, 2019 4:17 PM
  • Run it like this:

    wshShell.Run "cscript.exe " & strToolboxFolder & "\ReturnOU.vbs",1,True

    If your toolbox folder has spaces in it use:

    wshShell.Run "cscript.exe " & chr(34) & strToolboxFolder & "\ReturnOU.vbs" & chr(34) ,1,True

    The "True" will tell the HTA to wait for the script to complete. 

    The "1" will display the window. If your script does any wscript.echo, you will see those.

    Change it to 0 to hide the window.

    Friday, March 15, 2019 6:00 PM
  • So I was thinking... when I open an admin command prompt, any process that I launch from that window inherits admin mode. I don't get any UAC prompts for them. So the cscript.exe that you launch will inherit the rights of its parent process, mshta.exe. It will be interesting to see if the HTA calling a VBS works. Before your script terminates, put in a msgbox "Check script window" so that you can look at the window output for errors before cscript.exe terminates. 

    Having said all of that, I would recommend that you give up on HTA's. Go download Microsoft's free Visual Studio Community addition and build yourself a little VB forms application. You'll have a learning curve at first, but in the long run you will better off. You can insert code snippets and set breakpoints where you can walk through the code to see what it is doing. 

    Friday, March 15, 2019 6:32 PM
  • I know to do the message box thing, but I've been so busy and then trying to fix this on the side, that I didn't even think to do it.  So thanks for that reminder.  Now I've narrowed it down to populating the temp file with what it found in AD, so it's gotten quite far.  Much further than I originally thought.  I'll update the thread when I get a moment to test more.  I'm thinking of trying to populate an existing file and see if it'll do that vs the temp file.

    More to follow.

    Monday, March 18, 2019 4:33 PM
  • I take back what I said.  I think I may have had Resume next on error re-enabled.  It seem that as long as it's launched from within the hta, seems it's governed by the rules for the hta.  It errors on Set objConnection = CreateObject("ADODB.Connection"), but if I just double click the exact same .vbs then it works as it should.

    I appreciate what you say about giving up on HTAs.  But what I like about it is that you don't have to compile it and install it to use it.  I make updates rather often and have in the file to check and see if there's a newer version, if so, copy and overwrite itself and then restart.  This way the users are completely unaware of updates unless they observe the version number or read version update notes.  From what I've seen I don't think this is possible with regular VB.  also up until now, the HTA hasn't required admin rights to work as desired, installing a VB app would, I think.

    • Edited by Carl_S_S Monday, March 18, 2019 6:15 PM
    Monday, March 18, 2019 6:10 PM
  • All of that is at least 10 times easier in PowerShell.  Nothing ever needs to be compiled.


    Monday, March 18, 2019 6:39 PM
  • I learned a little about PowerShell, but not a lot and haven't looked at it in years.  I didn't think you could have a user interface with it like you can an HTA.  My main desire for this tool is ease of use for my non-technical users.  With my current tool, they don't need to know much, except for what they want to know.  They copy the HTA to their desktop, and double click, they want to lookup this or that, they just click a button and answer popup questions as required.  Can this be achieved with PowerShell?
    Monday, March 18, 2019 8:28 PM
  •  I didn't think you could have a user interface with it like you can an HTA. 

    Want to put some money on that?

    Copy and paste this at a ps prompt.

    Add-Type -AssemblyName System.Windows.Forms
    # control creation
    $form = New-Object System.Windows.Forms.Form
    $buttonOK = New-Object System.Windows.Forms.Button
    # form settings
    $form.StartPosition = 'CenterScreen'
    $form.Text = 'Basic Form Demo'
    # buttonOK settings
    $buttonOK.Text = 'Ok'
    $buttonOK.DialogResult = 'Ok'


    Monday, March 18, 2019 9:22 PM
  • In the "old" VB6 and earlier days you had to go though an install process mainly to get all the controls installed on the client. With .Net all(?) most(?) of that is in the Framework that's already on the client. Caveat, as a server admin, the code that I wrote would be classified as mostly utilities. Ie a program to manage McAfee client upgrades on servers. I used mostly basic controls, buttons, listboxes, etc. So I just copied the .exe to the server and ran it. The only real issue that I had was that I also had to copy a config file that listed the Framework versions that my code supported. (Due to my environment.) So I don't know if everything that your code might need will be on the client. 

    Jrv can better answer the Powershell UI question than me.   

    Build a "hello world" form app in VB.Net and Powershell. Add a button that does a basic query (whatever your app does). Give them both a test drive.  
    Monday, March 18, 2019 9:52 PM
  • PowerShell has all controls and needs no compiling.  It can be built in notepad, VSCode or PowerShell ISE.

    Nearly all vendors have support for PowerShell.  All major database and AV vendors supply custom commands for PowerShell.. 

    There will be no further development or support for VBS and HTA from Microsoft.  All references to both are being removed from the MS site and what remains is very hard to find.

    No one should be doing any new work with VBS WSH or HTA scripts.  These and CMD.EXE will likely be remove in the next major release of Windows.  All new releases from WS2019 and later have PowerShell as the default command processor.


    Monday, March 18, 2019 10:26 PM