Solved

Using GetObject in Javascript/VBscript combo

Posted on 2011-03-03
2
1,473 Views
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

-----------------------------------------------------------------------------------------------------------------
<html>
<head>
<title>User Transfer</title>
</head>

<body>

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

<p>
<br><br>
Welcome to the User Transfer page !
<br><br>

Select user who is moving :  

//Create dropdown list

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

</p>

<script language = "Javascript">

//document.bgColor = 'Skyblue'

</script>


<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)

Else

' *** 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

ADRecordSet.Close
ADConnection.Close

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

ResultsFile.Close

'----------------------------------------------------------------------------------------------------------------

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) & "."
Next

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

Set RootLDAP = Nothing

End Function

'----------------------------------------------------------------------------------------------------------------



'----------------------------------------------------------------------------------------------------------------
-->
</script>

</body>
</html>
0
Comment
Question by:DoveSupport
2 Comments
 
LVL 65

Accepted Solution

by:
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.

Regards,

Rob.
0
 
LVL 1

Author Closing Comment

by:DoveSupport
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 !
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
This article discusses how to create an extensible mechanism for linked drop downs.
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…

760 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now