Jump to content

Avoid AD query failure if computer is not in AD


Recommended Posts

Hi!

I'm "messing" around with the UDF "adfunctions.au3".

When running a script using this UDF on a non-AD computer,

I get the following error message (- even when no AD functions are called):

C:\TEMP\_\AUTOIT\Include\ADFunctions\ADFunctions.au3 (104) : ==> Variable must be of type "Object".:

Global $strDNSDomain = $objRootDSE.Get("defaultNamingContext")

Global $strDNSDomain = $objRootDSE^ ERROR

How could I avoid the error and keep the script running?

Setting an error handler couldn't this (yet).

Any Ideas?

Greets,

-supersonic.

Link to comment
Share on other sites

Hi!

I'm "messing" around with the UDF "adfunctions.au3".

When running a script using this UDF on a non-AD computer,

I get the following error message (- even when no AD functions are called):

C:\TEMP\_\AUTOIT\Include\ADFunctions\ADFunctions.au3 (104) : ==> Variable must be of type "Object".:

Global $strDNSDomain = $objRootDSE.Get("defaultNamingContext")

Global $strDNSDomain = $objRootDSE^ ERROR

How could I avoid the error and keep the script running?

Setting an error handler couldn't this (yet).

Any Ideas?

Greets,

-supersonic.

That UDF unconditionally initializes some domain related global variables by running some COM functions at run time without any of its UDF functions being called yet. I don't care for that and believe that makes it a poorly behaved UDF, but maybe that's just me.

You need a COM error handler to handle these errors gracefully.

Another option is to put that portion of the initialization in a function of its own, like _AD_Init(), and only run that to initialize those globals when you expect to be on a domain.

^_^

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Thank you for the answer.

I added:

If IsObj($oRootDSE) = 0 Then Return ""

... this helped me out.

That UDF unconditionally initializes some domain related global variables by running some COM functions at run time without any of its UDF functions being called yet. I don't care for that and believe that makes it a poorly behaved UDF, but maybe that's just me.

You need a COM error handler to handle these errors gracefully.

Another option is to put that portion of the initialization in a function of its own, like _AD_Init(), and only run that to initialize those globals when you expect to be on a domain.

^_^

Edited by supersonic
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...