Using GetObject in Javascript/VBscript combo

Posted on 2011-03-03
Last Modified: 2012-05-11
Hi Experts

Please could someone point me in the right direction ? I'm fairly ok with vbscript, and am now trying to combine with javascript.

My purpose is to present some choices, on a form, and use vbscript in the background to animate these choices and act upon them, to make changes to an AD user account.

In essence, I know that GetObject won't work in pure html, which is why I tried to enclose it in the vbscript section. The code below - in the GetDNSDomain() function - still pops up saying "ActiveX component can't create object : 'GetObject' "

How do I keep the vbscript - which I know works and I know how to use - and also have the javascript and form components ?

My attempt is posted below. It is a work in progress.

Many thanks in advance

<title>User Transfer</title>


<div align="center">User Transfer Utility</div></u></b></h1>

Welcome to the User Transfer page !

Select user who is moving :  

//Create dropdown list

<select name="Usernames" id="Usernames">


<script language = "Javascript">

//document.bgColor = 'Skyblue'


<script language = "VBScript">

Option Explicit

Const ForReading = 1, ForWriting = 2, ForAppending = 8, AccountEnabled = &H0002

Const WorkingDataFolder  = "C:\Scripts"
Const WorkingInputFile   = "C:\Scripts\ADUserListing.xlsx"
Const WorkingResultsFile = "C:\Scripts\UserMoveResults.csv"

Dim fso, DataFolder, InputFile, ResultsFile, HomeFolderPath, HomeDrive, ProfilePath, AccountEnabledFlag, AccountState
Dim CanoName, CNArray
Dim objUserID, objProfilePath, objUserPath, ADConnection, ADCommand, ADRecordSet
Dim DomainName, k


'On Error Resume Next


Set fso = CreateObject("Scripting.FileSystemObject")

' *** Check for data folder existense, if not found then create

If Not fso.FolderExists(WorkingDataFolder) Then
   Set DataFolder = fso.CreateFolder(WorkingDataFolder)
End If


' *** check for output file
If fso.FileExists(WorkingResultsFile) Then

' *** if output file exists, append information to it

   Set ResultsFile = fso.OpenTextFile(WorkingResultsFile, ForAppending)


' *** if output file does not exist, create for writing to it

    Set ResultsFile = fso.CreateTextFile(WorkingResultsFile, ForWriting)

End If


' *** Call function to get current Domain Name
DomainName = GetDNSDomain


' *** Setup an ADO query to Active Directory

Set ADConnection = CreateObject("ADODB.Connection")

ADConnection.Provider = "ADsDSOObject"
ADConnection.Open "Active Directory Provider"

Set ADCommand = CreateObject("ADODB.Command")
Set ADCommand.ActiveConnection = ADConnection

ADCommand.Properties("Page Size") = 1000
ADCommand.Properties("Searchscope") = 2


' *** close down all links and files


Set ADRecordSet = Nothing
Set ADConnection = Nothing
Set ADCommand = Nothing



Function GetDNSDomain()

Dim RootLDAP  
Dim strDNSDomain
Dim strArray    
Dim n            

' *** Commands to late bind to AD and extract domain name
Set RootLDAP = GetObject("LDAP://RootDSE")

strDNSDomain = RootLDAP.Get("DefaultNamingContext")

' *** strDNSDomain now contains a string that looks like this:   "DC=domain,DC=com"

strArray = Split(strDNSDomain, ",")
GetDNSDomain = ""

For n = 0 To UBound(strArray)
   GetDNSDomain = GetDNSDomain & Mid(strArray(n), 4) & "."

n = Len(GetDNSDomain)
If n > 1 Then
   GetDNSDomain = Left(GetDNSDomain, n - 1)
   GetDNSDomain = ""
End If

Set RootLDAP = Nothing

End Function



Question by:DoveSupport
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
LVL 65

Accepted Solution

RobSampson earned 250 total points
ID: 35032178
Hi, if you get "ActiveX component can't create object" it's usually a security issue, because by default, client side code can't create objects.

One thing you can try is add the website to your Trusted Sites zone, and make sure the security settings for that zone are set to allow ActiveX scripting.



Author Closing Comment

ID: 35036816
Thanks for that, Rob. Problem seems solved.
I was wondering why all the forums never mentioned problems with vbscript and javascript working together - goes to show there's always something else getting in the way !

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In Part 1 ( we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

739 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