Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1576
  • Last Modified:

Using GetObject in Javascript/VBscript combo

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



1 Solution
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.


DoveSupportAuthor Commented:
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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now