Jump to content

AD.au3 + ADfunctions.au3 = ADFunk.au3


Kovacic
 Share

Recommended Posts

AD.au3 vs. ADfunctions.au3, now play nice.

I ran into an interesting problem recently when I was pulling old code from 2 other tools I wrote. one uses AD.au3 and one uses ADfunctions.au3. I found out that including both will break your script, because they share many of the same functions and global variables. If you have ran into this and are stuck, let me know because I have bound the 2 together into one include called ADFunk.au3. It contains both files with no conflicts, including all global variables and functions.

Both includes credit goes to Jonathan Clelland (jclelland@statestreet.com), all I did was bind them and remove some duplicate values.

Enjoy!

___________________________________

After much testing, Just use AD.au3, I am removing ADFunk.

Edited by Kovacic

C0d3 is P0etry( ͡° ͜ʖ ͡°)

Link to comment
Share on other sites

Is there a reason why you need both UDFs in one script? AD.au3 is the successor of adfunctions.au3 and should contain all functions from adfunctions.au3.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Is there a reason why you need both UDFs in one script? AD.au3 is the successor of adfunctions.au3 and should contain all functions from adfunctions.au3.

I actually had scripts that used either one, but I did try using only one include but it didn't work.

As an example, one script uses a function _ADSamAccountNameToFQDN as where the other uses _AD_SamAccountNameToFQDN (notice the extra underline) so some of the functions did change. While I could have gone through all my scripts and crossed referenced each function, I found this to be a better option for me.

Edited by Kovacic

C0d3 is P0etry( ͡° ͜ʖ ͡°)

Link to comment
Share on other sites

I had a look at your combined UDF. If it works - fine. But if it doesn't then it will be hard to debug. I support AD.au3 but I can't give support for adfunctions.au3 nor the combined UDF in case of problems.

The combined UDF always opens a connection to AD even when you just need functions from AD.au3. All scripts working with AD.au3 need to call _AD_Open to connect to the Active Directory. So some of your scripts do it twice - which might lead to problems.

Your combined UDF always needs to be modified when the AD.au3 is updated.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

  • Moderators

Kovacic, I posted much the same question as Water did here, in your original post in the AutoIt users forum on LinkedIn. I think it is confusing to the users on that forum if you go presenting your combined UDF as "the answer", when AD.au3 does everything a person would need to do.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

Kovacic, I posted much the same question as Water did here, in your original post in the AutoIt users forum on LinkedIn. I think it is confusing to the users on that forum if you go presenting your combined UDF as "the answer", when AD.au3 does everything a person would need to do.

As stated earlier, even though AD.au3 is much larger than adfunctions.au3, not all functions are included. At the moment, I don't have time to run through the various functions and compare the two, but if AD contained everything ADfunctions had, I would not have combined them.

This is not meant to be an answer to a problem, only something that helped me out with a problem I was having, and I figured others could use it too.

Edited by Kovacic

C0d3 is P0etry( ͡° ͜ʖ ͡°)

Link to comment
Share on other sites

Also as a side note, When you try to perform an action in AD, and get " -2147352567 " as a return error, that means the account in use does not have permission to perform that action in active directory. Would be a good addition to AD.au3 error codes.

C0d3 is P0etry( ͡° ͜ʖ ͡°)

Link to comment
Share on other sites

No, it doesn't. The decimal value is the HRESULT value of 0x80020009 in hex and means DISP_E_EXCEPTION (Exception occurred) according to MSDN.

You need a COM error handler to get the error description which then tells you what is the cause of the error.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

No, it doesn't. The decimal value is the HRESULT value of 0x80020009 in hex and means DISP_E_EXCEPTION (Exception occurred) according to MSDN.

You need a COM error handler to get the error description which then tells you what is the cause of the error.

In the snippit below, when I ran the app without proper domain credentials, I got an unspecified error return of -2147352567, when I ran it with domain credentials, it worked fine and moved the computer as needed.

That was the only time I got that return code from AD, so that's what leads me to think that is the case.

If $oumove = "yes"then
$sTargetOU = $compouV
$sObject = @ComputerName
_AD_Open()
Global $iValue = _AD_MoveObject($sTargetOU, $sObject & "$")
If $iValue = 1 Then
MsgBox(64, "Active Directory Message", "Computer '" & $sObject & "' successfully moved to '" & $sTargetOU & "'")
ElseIf @error = 1 Then
MsgBox(64, "Active Directory Message", "Target OU '" & $sTargetOU & "' does not exist")
ElseIf @error = 2 Then
MsgBox(64, "Active Directory Message", "Computer '" & $sObject & "' does not exist")
ElseIf @error = 3 Then
MsgBox(64, "Active Directory Message", "Computer '" & $sObject & "' is already in the required OU. No change made.")
ElseIf @error = "-2147352567" Then
MsgBox(64, "Active Directory Message", "Could not move '" & $sObject & "'. You do not have write access to Active Directory.")
Else
MsgBox(64, "Active Directory Message", "Return code '" & @error & "' from Active Directory")
EndIf
_AD_Close()
Else
;MsgBox(64, "Active Directory Message", "No OU moves were performed because the User account is not in a Users OU.")
exit
EndIf

C0d3 is P0etry( ͡° ͜ʖ ͡°)

Link to comment
Share on other sites

Is there a reason why you need both UDFs in one script? AD.au3 is the successor of adfunctions.au3 and should contain all functions from adfunctions.au3.

not trying to make enemies when I just got here.. The reason I combined the two is because the function names appear to have changed, and some functions seem to have been changed. As an example, _ADObjectExists is now _AD_ObjectExists. If I use _ADObjectExists all through my codem then go from adfunctions to ad, its going to break my script. I am just saying that the names changed and I didn't see any mention of that in the description section of the script. Maybe the functions do the same thing, maybe they are different, I honestly don't know.

Example:

AD.au3:

Func _AD_ObjectExists($sAD_Object = @UserName, $sAD_Property = "")

If $sAD_Property = "" Then
$sAD_Property = "samAccountName"
If StringMid($sAD_Object, 3, 1) = "=" Then $sAD_Property = "distinguishedName"
EndIf
$__oAD_Command.CommandText = " Local $oAD_RecordSet = $__oAD_Command.Execute ; Retrieve the ADsPath for the object, if it exists
If IsObj($oAD_RecordSet) Then
If $oAD_RecordSet.RecordCount = 1 Then
Return 1
ElseIf $oAD_RecordSet.RecordCount > 1 Then
Return SetError($oAD_RecordSet.RecordCount, 0, 0)
Else
Return SetError(1, 0, 0)
EndIf
Else
Return SetError(1, 0, 0)
EndIf

EndFunc ;==>_AD_ObjectExists

ADFunctions:

Func _ADObjectExists($object)
$strQuery = " $objRecordSet = $ObjConnection.Execute ($strQuery) ; Retrieve the FQDN for the group, if it exists

If $objRecordSet.RecordCount = 1 Then
$objRecordSet = 0
Return 1
Else
$objRecordSet = 0
Return 0
EndIf
EndFunc ;==>_ADObjectExists

Don't get me wrong, I love the includes and they help me out allot, but like I said, as far as you are concerned, I am an end user having trouble with something that I tried to remedy. I take no credit for your code because it is so far past my level. All I am asking is that you see it from my point of view.

C0d3 is P0etry( ͡° ͜ʖ ͡°)

Link to comment
Share on other sites

..... The reason I combined the two is because the function names appear to have changed, and some functions seem to have been changed. ....

A word of advice - Feel free to ask us ANY TIME if you are not sure. We are happy to help. If anything I know Water will be happy to help you with your questions if you are not sure on how a piece of code works. Edited by YogiBear
Link to comment
Share on other sites

A word of advice - Feel free to ask us ANY TIME if you are not sure. We are happy to help. If anything I know Water will be happy to help you with your questions if you are not sure on how a piece of code works.

I will be happy to do that in the future. I just got bogged down and backed into a corner with the project I'm working on, and had to act. If he wants to add the functions or make changes and wants me to delete this post, then its fine with me, like I said, I'm not trying to step on toes.

On that note, I am going to take your advice right now..

I am stuck again, but I am sure it is something simple for you guys. Here is the post:

Edited by Kovacic

C0d3 is P0etry( ͡° ͜ʖ ͡°)

Link to comment
Share on other sites

... when I ran the app without proper domain credentials, I got an unspecified error return of -2147352567, when I ran it with domain credentials, it worked fine and moved the computer as needed.

Invalid credentials is on of the reasons why you get this error code. That's why using a COM error handler is useful because you get detailed information about the error. Use function _AD_ErrorNotify to activate the COM error handler and set the kind of output (ConsoleWrite, MsgBox, File).

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

not trying to make enemies when I just got here

You are not making enemies here. That takes a bit more ;)

The reason I combined the two is because the function names appear to have changed, and some functions seem to have been changed.

Correct. I've taken the adfunctions written by Jonathan Clelland and enhanced them (adding help file, inline documentation, examle scripts, SciTE integration). Over time users asked for more so new features and functions were added.

It's quite easy to decide which include you need: Function name _AD* => adfunctions; function name: _AD_* => AD.au3

It's a valid goal to make your work as easy as possible. I just wanted to point out that combining the two UDFs could lead to undesired results because the design is so different. I'm happy to support the UDFs I have written but I can't help with a combined UDF.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share

  • Recently Browsing   0 members

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