Sign in to follow this  
Followers 0
ScriptingSteve

Nested OBjects in AutoIt

3 posts in this topic

I am trying to convert this VBscript to Autoit 3.2.0.1:

On Error Resume Next

Const ADS_SCOPE_SUBTREE = 2

Set objRootDSE = GetObject("LDAP://RootDSE")

strConfigurationNC = objRootDSE.Get("configurationNamingContext")

Set objConnection = CreateObject("ADODB.Connection")

Set objCommand = CreateObject("ADODB.Command")

objConnection.Provider = "ADsDSOObject"

objConnection.Open "Active Directory Provider"

Set objCommand.ActiveConnection = objConnection

objCommand.Properties("Page Size") = 1000

objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE

objCommand.CommandText = _

"SELECT ADsPath FROM 'LDAP://" & strConfigurationNC & "' WHERE objectClass='nTDSDSA'"

Set objRecordSet = objCommand.Execute

objRecordSet.MoveFirst

Do Until objRecordSet.EOF

Set objParent = GetObject(GetObject(objRecordset.Fields("ADsPath")).Parent)

WScript.Echo objParent.CN

objRecordSet.MoveNext

Loop

Unfortunately, AutoIt does not like my version of the line:

Set objParent = GetObject(GetObject(objRecordset.Fields("ADsPath")).Parent)

which I wrote in AutoIt as this line:

$objParent = ObjGet(ObjGet($objRecordset.Fields("ADsPath")).Parent)

It aborts with the error: "Object referenced outside a "With" statement.: "

I've attached my code, which is intended to be a Function for another script. Can anyone assist with the syntax? The VB script version works fine, and is pulled right from Microsoft.

Thanks!

Share this post


Link to post
Share on other sites



I am trying to convert this VBscript to Autoit 3.2.0.1:

....

Unfortunately, AutoIt does not like my version of the line:

Set objParent = GetObject(GetObject(objRecordset.Fields("ADsPath")).Parent)

which I wrote in AutoIt as this line:

$objParent = ObjGet(ObjGet($objRecordset.Fields("ADsPath")).Parent)

It aborts with the error: "Object referenced outside a "With" statement.: "

....

Thanks!

Hello 'ScriptingSteve',

Autoit is not built as being a full fledged OOP (object oriented programming) language. Actually the AutoIt COM/Object support does only 'emulate' OOP-like behaviour.

If a function xxxx returns variable type yyyy, it does not mean that you can immediately use a statement like xxxx.zzzz, where zzzz refers to variable type yyyy. You need an intermediate variable to perform this action.

To 'convert' your VBscript code to AutoIt code you need to rewrite all nested object-function calls like this:

; conversion for $objParent = ObjGet(ObjGet($objRecordset.Fields("ADsPath")).Parent)

$ObjTemp = ObjGet($objRecordset.Fields("ADsPath"))
$objParent = ObjGet($ObjTemp.parent)

Regards,

-Sven

Share this post


Link to post
Share on other sites

Thanks... I did try that, it didn't seem to work - perhaps I will try again.

Thanks for your help.

Hello 'ScriptingSteve',

Autoit is not built as being a full fledged OOP (object oriented programming) language. Actually the AutoIt COM/Object support does only 'emulate' OOP-like behaviour.

If a function xxxx returns variable type yyyy, it does not mean that you can immediately use a statement like xxxx.zzzz, where zzzz refers to variable type yyyy. You need an intermediate variable to perform this action.

To 'convert' your VBscript code to AutoIt code you need to rewrite all nested object-function calls like this:

; conversion for $objParent = ObjGet(ObjGet($objRecordset.Fields("ADsPath")).Parent)

$ObjTemp = ObjGet($objRecordset.Fields("ADsPath"))
$objParent = ObjGet($ObjTemp.parent)

Regards,

-Sven

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0