Sign in to follow this  
Followers 0
jazzyjeff

_AD_Open function problem

5 posts in this topic

Hello,

I am using the _AD_Open() function to move a PC to a selected OU. After getting help from Water this works great.

All my testing was using my PC, which is joined to the domain and has access to create accounts in AD. The problem is the script needs to be used on PCs that are not joined to the domain.

My script creates/joins the PC to the domain (I can see it in AD). The problem is it thinks the PC is not joined to the domain.

I think my problem lies with the parameter $sAD_ConfigurationParam.

I am going to post the script, so it'll provide a better understanding of what I am trying to achieve. Basically after an image I log into the PC and run this script. The script will modify the computer description, join it to the domain, add it to the specific OU, create a startup shortcut that will launch another script at login, add autologin credentials(the next script deletes these) and then run a BIOS update (this reboots the PC).

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <GUIListView.au3>
#include <WindowsConstants.au3>
#include <AD.au3>
#include <Array.au3>

Opt("WinWaitDelay",100)
Opt("WinDetectHiddenText",1)
Opt("MouseCoordMode",0)
Opt("SendKeyDelay",17)

; Add Computer Description
$CompDesc = InputBox("Computer Description","Enter: Lastname, Firstname","")
RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\LanmanServer\Parameters","srvcomment","REG_SZ",$CompDesc)

; Select School Building
Global $sch="BLAIR|CENTRAL GRADE|CHERRYKNOLL|COURTADE|EASTERN|INTERLOCHEN|LONG LAKE|MONTESSORRI|OLD MISSION|SILVER LAKE|TRAVERSE HEIGHTS|WESTWOODS|WILLOW HILL|CENTRAL HIGH SCHOOL|EAST MIDDLE SCHOOL|TRAVERSE CITY HIGH SCHOOL|WEST MIDDLE SCHOOL|WEST HIGH SCHOOL"
Global $iMax
Global $i
Global $arr = StringSplit($sch, "|")
If IsArray($arr) Then
    $iMax = UBound($arr)
For $i = 0 to $iMax - 1
    Next
EndIf

#region ### START Koda GUI section ###
$main1 = GUICreate("Select School", 298, 344, 192, 124)
$ListSch = GUICtrlCreateList("", 7, 8, 281, 279, BitOR($LBS_STANDARD, $LBS_EXTENDEDSEL, $WS_VSCROLL, $WS_BORDER))
GUICtrlSetData($ListSch, $sch)
$btnCont1 = GUICtrlCreateButton("Continue", 7, 294, 281, 41, $WS_GROUP)
GUICtrlSetFont(-1, 20, 400, 0, "Impact")
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###

    While 1
        $nMsg = GUIGetMsg()

        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                Exit
            Case $btnCont1
                $selSch = _GUICtrlListBox_GetSelItems($ListSch)
                Global $selectedSch = $selSch[1]
                    If $SelectedSch = 0 Then
                        _BL()
                    EndIf
                    If $SelectedSch = 1 Then
                        _CE()
                    EndIf
                    If $SelectedSch = 3 Then
                        _CK()
                    EndIf
                    If $SelectedSch = 4 Then
                        _CO()
                    EndIf
                    If $SelectedSch = 6 Then
                        _EA()
                    EndIf
                    If $SelectedSch = 7 Then
                        _IN()
                    EndIf
                    If $SelectedSch = 8 Then
                        _LL()
                    EndIf
                    If $SelectedSch = 9 Then
                        _MO()
                    EndIf
                    If $SelectedSch = 10 Then
                        _OM()
                    EndIf
                    If $SelectedSch = 11 Then
                        _SL()
                    EndIf
                    If $SelectedSch = 13 Then
                        _TH()
                    EndIf
                    If $SelectedSch = 16 Then
                        _WW()
                    EndIf
                    If $SelectedSch = 17 Then
                        _WH()
                    EndIf
                    If $SelectedSch = 2 Then
                        _CHS()
                    EndIf
                    If $SelectedSch = 5 Then
                        _EMS()
                    EndIf
                    If $SelectedSch = 12 Then
                        _TCHS()
                    EndIf
                    If $SelectedSch = 15 Then
                        _WMS()
                    EndIf
                    If $SelectedSch = 14 Then
                        _WHS()
                    EndIf
            Exit
        EndSwitch
    WEnd

Func _BL()
    MsgBox(1,"School Building","You are running scripts for Blair.",5)
    ; Create shortcut to launch Fast Install Script
    FileCopy("E:\Shortcuts\BL\Teacher-Install.lnk","c:\Documents and Settings\All Users\Start Menu\Programs\Startup\",1)
    ;Call the next functions
    Call("_JoinDomain")
    Call("_AutoLogin")
    Call("_DellBIOS")

EndFunc

Func _CE()
    MsgBox(1,"School Building","You are running scripts for Central Grade.",5)
    ; Create shortcut to launch Fast Install Script
    FileCopy("E:\Shortcuts\CE\Teacher-Install.lnk","c:\Documents and Settings\All Users\Start Menu\Programs\Startup\",1)
    ;Call the next functions
    Call("_JoinDomain")
    Call("_AutoLogin")
    Call("_DellBIOS")

EndFunc

Func _CK()
    MsgBox(1,"School Building","You are running scripts for Cherryknoll.",5)
    ; Create shortcut to launch Fast Install Script
    FileCopy("E:\Shortcuts\CK\Teacher-Install.lnk","c:\Documents and Settings\All Users\Start Menu\Programs\Startup\",1)
    ;Call the next functions
    Call("_JoinDomain")
    Call("_AutoLogin")
    Call("_DellBIOS")

EndFunc

Func _CO()
    MsgBox(1,"School Building","You are running scripts for Eastern.",5)
    ; Create shortcut to launch Fast Install Script
    FileCopy("E:\Shortcuts\CO\Teacher-Install.lnk","c:\Documents and Settings\All Users\Start Menu\Programs\Startup\",1)
    ;Call the next functions
    Call("_JoinDomain")
    Call("_SelectOU")
    Call("_AutoLogin")
    Call("_DellBIOS")

EndFunc

Func _EA()
    MsgBox(1,"School Building","You are running scripts for Eastern.",5)
    ; Create shortcut to launch Fast Install Script
    FileCopy("E:\Shortcuts\EA\Teacher-Install.lnk","c:\Documents and Settings\All Users\Start Menu\Programs\Startup\",1)
    ;Call the next functions
    Call("_JoinDomain")
    Call("_SelectOU")
    Call("_AutoLogin")
    Call("_DellBIOS")

EndFunc

Func _IN()
    MsgBox(1,"School Building","You are running scripts for Interlochen.",5)
    ; Create shortcut to launch Fast Install Script
    FileCopy("E:\Shortcuts\IN\Teacher-Install.lnk","c:\Documents and Settings\All Users\Start Menu\Programs\Startup\",1)
    ;Call the next functions
    Call("_JoinDomain")
    Call("_SelectOU")
    Call("_AutoLogin")
    Call("_DellBIOS")

EndFunc

Func _LL()
    MsgBox(1,"School Building","You are running scripts for Long Lake.",5)
    ; Create shortcut to launch Fast Install Script
    FileCopy("E:\Shortcuts\LL\Teacher-Install.lnk","c:\Documents and Settings\All Users\Start Menu\Programs\Startup\",1)
    ;Call the next functions
    Call("_JoinDomain")
    Call("_SelectOU")
    Call("_AutoLogin")
    Call("_DellBIOS")

EndFunc

Func _MO()
    MsgBox(1,"School Building","You are running scripts for Montessorri.",5)
    ; Create shortcut to launch Fast Install Script
    FileCopy("E:\Shortcuts\MO\Teacher-Install.lnk","c:\Documents and Settings\All Users\Start Menu\Programs\Startup\",1)
    ;Call the next functions
    Call("_JoinDomain")
    Call("_SelectOU")
    Call("_AutoLogin")
    Call("_DellBIOS")

EndFunc

Func _OM()
    MsgBox(1,"School Building","You are running scripts for Old Mission.",5)
    ; Create shortcut to launch Fast Install Script
    FileCopy("E:\Shortcuts\OM\Teacher-Install.lnk","c:\Documents and Settings\All Users\Start Menu\Programs\Startup\",1)
    ;Call the next functions
    Call("_JoinDomain")
    Call("_SelectOU")
    Call("_AutoLogin")
    Call("_DellBIOS")

EndFunc

Func _SL()
    MsgBox(1,"School Building","You are running scripts for Silver Lake.",5)
    ; Create shortcut to launch Fast Install Script
    FileCopy("E:\Shortcuts\SL\Teacher-Install.lnk","c:\Documents and Settings\All Users\Start Menu\Programs\Startup\",1)
    ;Call the next functions
    Call("_JoinDomain")
    Call("_SelectOU")
    Call("_AutoLogin")
    Call("_DellBIOS")

EndFunc

Func _TH()
    MsgBox(1,"School Building","You are running scripts for Traverse Heights.",5)
    ; Create shortcut to launch Fast Install Script
    FileCopy("E:\Shortcuts\TH\Teacher-Install.lnk","c:\Documents and Settings\All Users\Start Menu\Programs\Startup\",1)
    ;Call the next functions
    Call("_JoinDomain")
    Call("_SelectOU")
    Call("_AutoLogin")
    Call("_DellBIOS")

EndFunc

Func _WW()
    MsgBox(1,"School Building","You are running scripts for Westwoods.",5)
    ; Create shortcut to launch Fast Install Script
    FileCopy("E:\Shortcuts\WW\Teacher-Install.lnk","c:\Documents and Settings\All Users\Start Menu\Programs\Startup\",1)
    ;Call the next functions
    Call("_JoinDomain")
    Call("_SelectOU")
    Call("_AutoLogin")
    Call("_DellBIOS")

EndFunc

Func _WH()
    MsgBox(1,"School Building","You are running scripts for Willow Hill.",5)
    ; Create shortcut to launch Fast Install Script
    FileCopy("E:\Shortcuts\WH\Teacher-Install.lnk","c:\Documents and Settings\All Users\Start Menu\Programs\Startup\",1)
    ;Call the next functions
    Call("_JoinDomain")
    Call("_SelectOU")
    Call("_AutoLogin")
    Call("_DellBIOS")

EndFunc

Func _CHS()
    MsgBox(1,"School Building","You are running scripts for Central High School.",5)
    ; Create shortcut to launch Fast Install Script
    FileCopy("E:\Shortcuts\CHS\Teacher-Install.lnk","c:\Documents and Settings\All Users\Start Menu\Programs\Startup\",1)
    ;Call the next functions
    Call("_JoinDomain")
    Call("_SelectOU")
    Call("_AutoLogin")
    Call("_HPBIOS")

EndFunc

Func _EMS()
    MsgBox(1,"School Building","You are running scripts for East Middle School.",5)
    ; Create shortcut to launch Fast Install Script
    FileCopy("E:\Shortcuts\EMS\Teacher-Install.lnk","c:\Documents and Settings\All Users\Start Menu\Programs\Startup\",1)
    ;Call the next functions
    Call("_JoinDomain")
    Call("_SelectOU")
    Call("_AutoLogin")
    Call("_HPBIOS")

EndFunc

Func _TCHS()
    MsgBox(1,"School Building","You are running scripts for Traverse City High School.",5)
    ; Create shortcut to launch Fast Install Script
    FileCopy("E:\Shortcuts\TCHS\Teacher-Install.lnk","c:\Documents and Settings\All Users\Start Menu\Programs\Startup\",1)
    ;Call the next functions
    Call("_JoinDomain")
    Call("_SelectOU")
    Call("_AutoLogin")
    Call("_HPBIOS")

EndFunc

Func _WMS()
    MsgBox(1,"School Building","You are running scripts for West Middle School.",5)
    ; Create shortcut to launch Fast Install Script
    FileCopy("E:\Shortcuts\WMS\Teacher-Install.lnk","c:\Documents and Settings\All Users\Start Menu\Programs\Startup\",1)
    ;Call the next functions
    Call("_JoinDomain")
    Call("_SelectOU")
    Call("_AutoLogin")
    Call("_HPBIOS")

EndFunc

Func _WHS()
    MsgBox(1,"School Building","You are running scripts for West High School.",5)
    ; Create shortcut to launch Fast Install Script
    FileCopy("E:\Shortcuts\WHS\Teacher-Install.lnk","c:\Documents and Settings\All Users\Start Menu\Programs\Startup\",1)
    ;Call the next functions
    Call("_JoinDomain")
    Call("_SelectOU")
    Call("_AutoLogin")
    Call("_HPBIOS")

EndFunc

Func _DellBIOS()
    ; Install BIOS
    Run("C:\Windows\!DriverCache\D830_A15.exe")
    _WinWaitActivate("Dell BIOS Flash","")
    Send("{ENTER}")
    _WinWaitActivate("Latitude D830 BIOS Flash A15","")
    Send("{ENTER}")
EndFunc

Func _HPBIOS()
    ; Install BIOS
    Run("C:\Windows\!DriverCache\HP6710Bios-F15\HPQFlash.exe")
    _WinWaitActivate("HPQ Flash Wizard","Welcome to the HPQ F")
    Send("{ENTER}")
    _WinWaitActivate("HPQ Flash Wizard","The BIOS is protecte")
    Send("peps1{ENTER}")
    _WinWaitActivate("HPQ Flash Wizard","Verify whether you w")
    Send("{ENTER}")
EndFunc

Func _JoinDomain()
    ; Join PC to domain
    Send("{LWINDOWN}r{LWINUP}")
    _WinWaitActivate("Run","Type the name of a p")
    Send("sysdm.cpl{ENTER}")
    _WinWaitActivate("System Properties","Microsoft Windows XP")
    Send("{RIGHT}")
    _WinWaitActivate("System Properties","Computer &descriptio")
    Send("{ALTDOWN}cd{ALTUP}")
    _WinWaitActivate("Computer Name Changes","You can change the n")
    Send("{TAB}domain.net{ENTER}")
    _WinWaitActivate("Computer Name Changes","&User name:")
    Send("username{TAB}password{ENTER}")
    _WinWaitActivate("Computer Name Changes","Welcome to the tcaps")
    Send("{ENTER}")
    _WinWaitActivate("Computer Name Changes","You must restart thi")
    Send("{ENTER}")
    _WinWaitActivate("System Properties","Computer &descriptio")
    Send("{TAB}{ENTER}")

EndFunc

Func _AutoLogin()
    ; Setup AutoLogin
    RegWrite("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon", "DefaultUserName", "REG_SZ", "username")
    RegWrite("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon", "DefaultDomainName", "REG_SZ", "domain")
    RegWrite("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon", "AltDefaultUserName", "REG_SZ", "username")
    RegWrite("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon", "AltDefaultDomainName", "REG_SZ", "domain")
    RegWrite("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon", "DefaultPassword", "REG_SZ", "password")
    RegWrite("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon", "AutoAdminLogon", "REG_SZ", "1")
EndFunc

Func _SelectOU()

    ;Choose domain OU
    _AD_Open("username","password","DC=domain,DC=NET","servername.domain.net","CN=servername,DC=domain,DC=NET")

    Global $adOU = _AD_GetAllOUs()
    For $iCount = 20 To $adOU[0][0]
        If $iCount = 20 Then
            $sOU = $adOU[$iCount][0]
        Else
            $sOU = $sOU & "|" & $adOU[$iCount][0]
        EndIf

    Next

    #region ### START Koda GUI section ###
    $main2 = GUICreate("Active Directory", 298, 344, 192, 124)
    $ListOU = GUICtrlCreateList("", 7, 8, 281, 279, BitOR($LBS_SORT, $LBS_STANDARD, $LBS_EXTENDEDSEL, $WS_VSCROLL, $WS_BORDER))
    GUICtrlSetData($ListOU, $sOU)
    $btnCont2 = GUICtrlCreateButton("Continue", 7, 294, 281, 41, $WS_GROUP)
    GUICtrlSetFont(-1, 20, 400, 0, "Impact")
    GUISetState(@SW_SHOW)
    #endregion ### END Koda GUI section ###

    While 1
        $nMsg = GUIGetMsg()

        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                Exit
            Case $btnCont2
                $selOU = _GUICtrlListBox_GetSelItems($ListOU)
                Global $selectedItem = $selOU[1]+20
                Global $iValue = _AD_MoveObject($adOU[$selectedItem][1], @ComputerName & "$")
                If $iValue = 1 Then
                    MsgBox(64, "Successful", @ComputerName & " has now been moved to the following OU: " & $adOU[$selectedItem][0],7)
                ElseIf @error = 1 Then
                    MsgBox(64, "Fail","Organizational Unit (OU) " & $adOU[$selectedItem][0] & " does not exist")
                ElseIf @error = 2 Then
                    MsgBox(64, "Fail","Object " & @ComputerName & "$ does not exist")
                Else
                    MsgBox(64, "Active Directory Functions - Example 1", "Return code '" & @error & "' from Active Directory")
                EndIf
                Exit
        EndSwitch
    WEnd

    _AD_Close()
EndFunc

#region --- Internal functions Au3Recorder Start ---
Func _WinWaitActivate($title,$text,$timeout=0)
    WinWait($title,$text,$timeout)
    If Not WinActive($title,$text) Then WinActivate($title,$text)
    WinWaitActive($title,$text,$timeout)
EndFunc
#endregion --- Internal functions Au3Recorder End ---

#endregion --- Au3Recorder generated code End ---

To save you searching through all the code, here is the function that is causing the problem.

Func _SelectOU()

    ;Choose domain OU
    _AD_Open("username","password","DC=domain,DC=NET","servername.domain.net","CN=servername,DC=domain,DC=NET")

    Global $adOU = _AD_GetAllOUs()
    For $iCount = 20 To $adOU[0][0]
        If $iCount = 20 Then
            $sOU = $adOU[$iCount][0]
        Else
            $sOU = $sOU & "|" & $adOU[$iCount][0]
        EndIf

    Next

    #region ### START Koda GUI section ###
    $main2 = GUICreate("Active Directory", 298, 344, 192, 124)
    $ListOU = GUICtrlCreateList("", 7, 8, 281, 279, BitOR($LBS_SORT, $LBS_STANDARD, $LBS_EXTENDEDSEL, $WS_VSCROLL, $WS_BORDER))
    GUICtrlSetData($ListOU, $sOU)
    $btnCont2 = GUICtrlCreateButton("Continue", 7, 294, 281, 41, $WS_GROUP)
    GUICtrlSetFont(-1, 20, 400, 0, "Impact")
    GUISetState(@SW_SHOW)
    #endregion ### END Koda GUI section ###

    While 1
        $nMsg = GUIGetMsg()

        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                Exit
            Case $btnCont2
                $selOU = _GUICtrlListBox_GetSelItems($ListOU)
                Global $selectedItem = $selOU[1]+20
                Global $iValue = _AD_MoveObject($adOU[$selectedItem][1], @ComputerName & "$")
                If $iValue = 1 Then
                    MsgBox(64, "Successful", @ComputerName & " has now been moved to the following OU: " & $adOU[$selectedItem][0],7)
                ElseIf @error = 1 Then
                    MsgBox(64, "Fail","Organizational Unit (OU) " & $adOU[$selectedItem][0] & " does not exist")
                ElseIf @error = 2 Then
                    MsgBox(64, "Fail","Object " & @ComputerName & "$ does not exist")
                Else
                    MsgBox(64, "Active Directory Functions - Example 1", "Return code '" & @error & "' from Active Directory")
                EndIf
                Exit
        EndSwitch
    WEnd

    _AD_Close()
EndFunc

Thanks all for your help. Sorry for all these posts!

Share this post


Link to post
Share on other sites

#2 ·  Posted (edited)

To get the correct values for the _AD_Open() parameters run the following script:

#include <AD.au3>
_AD_Open()
ConsoleWrite($sAD_DNSDomain & @CRLF)
ConsoleWrite($sAD_HostServer & @CRLF)
ConsoleWrite($sAD_Configuration & @CRLF)
_AD_Close()

The $sAD_ConfigurationParameter has to point to the configuration naming context. In my case this is "CN=Configuration,DC=microsoft,DC=com". No servername required.

BTW: Good coding practice is to check the returncode of a function to handly any errors. _AD_Open() is not very good at returning errors at the moment but will improve as soon as I get a Windows 7 machine.

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Water,

Thanks again for your quick response. I now have the correct configuration LDAP path in my script.

I am now exhibiting a problem where an error message is returned, but it makes no sense to me at all.

I have checked everything, and it looks good to me.

I can confirm that the script works fine when a user is logged into the PC with a domain account, but a PC that is logged in with a workgroup account receives an AD error.

It makes me think the problem lies with whats happening in the _AD_Open part of the script. I am thinking that it's not authenticating properly, but maybe you have a better idea.

The script is moving a computer account from one OU to another.

Here is the part of the script that isn't functioning correctly:

Func _SelectOU()

    ;Choose domain OU
    _AD_Open("administrator", "password", "DC=domain,DC=net", "server.domain.net", "CN=Configuration,DC=domain,DC=net")

    Global $adOU = _AD_GetAllOUs()
    For $iCount = 20 To $adOU[0][0]
        If $iCount = 20 Then
            $sOU = $adOU[$iCount][0]
        Else
            $sOU = $sOU & "|" & $adOU[$iCount][0]
        EndIf

    Next

    #region ### START Koda GUI section ###
    $main2 = GUICreate("Active Directory", 298, 344, 192, 124)
    $ListOU = GUICtrlCreateList("", 7, 8, 281, 279, BitOR($LBS_SORT, $LBS_STANDARD, $LBS_EXTENDEDSEL, $WS_VSCROLL, $WS_BORDER))
    GUICtrlSetData($ListOU, $sOU)
    $btnCont2 = GUICtrlCreateButton("Continue", 7, 294, 281, 41, $WS_GROUP)
    GUICtrlSetFont(-1, 20, 400, 0, "Impact")
    GUISetState(@SW_SHOW)
    #endregion ### END Koda GUI section ###

    While 1
        $nMsg = GUIGetMsg()

        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                Exit
            Case $btnCont2
                ; Check what OU has been selected in the listbox
                $selOU = _GUICtrlListBox_GetSelItems($ListOU)
                Global $selectedItem = $selOU[1] + 20
                ;Create computer account in AD
                Global $iComp = _AD_CreateComputer("CN=Computers,DC=domain,DC=net",@ComputerName,"user")
                If $iComp = 1 Then
                    MsgBox(64, "Successful", @ComputerName & " is in the Domain.", 5)
                ElseIf @error = 1 Then
                    MsgBox(64, "Fail", "The Computers OU can not be found to create Computer account in AD.")
                ElseIf @error = 2 Then
                    MsgBox(64, "Fail", @ComputerName & " already exists in the Domain.")
                ElseIf @error = 3 Then
                    MsgBox(64, "Fail", "The user does not exist.")
                Else
                    MsgBox(64, "Active Directory Functions", "Creating Computer account - Return code '" & @error & "' from Active Directory")
                EndIf
                ;Join computer to AD account
                _AD_JoinDomain(@ComputerName)
                ;Move Computer to selected OU
                Global $iValue = _AD_MoveObject($adOU[$selectedItem][1], @ComputerName & "$")
                If $iValue = 1 Then
                    MsgBox(64, "Successful", @ComputerName & " has now been moved to the following OU: " & $adOU[$selectedItem][0], 7)
                ElseIf @error = 1 Then
                    MsgBox(64, "Fail", "Organizational Unit (OU) " & $adOU[$selectedItem][0] & " does not exist")
                ElseIf @error = 2 Then
                    MsgBox(64, "Fail", "Object " & @ComputerName & "$ does not exist")
                Else
                    MsgBox(64, "Active Directory Functions", "Move Computer account - Return code '" & @error & "' from Active Directory")
                EndIf
                Exit
        EndSwitch
    WEnd

    _AD_Close()
EndFunc   ;==>_SelectOU

I have also attached a screen shot of the error that I receive when it tries to move the computer to another OU.

post-54196-12761851180017_thumb.jpg

I have added extra lines of code to use your other functions to confirm the computer account exists and the computer account is joined to the domain.

Any help you can provide with this error message will be very much appreciated.

Edited by jazzyjeff

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

I hate this error code! It means "DISP_E_EXCEPTION - Unanticipated error occurred".

Some questions come to my mind:

  • Why do you create the computer account in the OU "CN=Computers,DC=tcaps,DC=net" and move it in a second step? You could create the computer in the OU selected by the user directly
  • With _AD_CreateComputer you define a user or group that is allowed to join the computer to the domain. In your case this is "sehi".

    You have to specify this userid and the password for "sehi" in the _AD_JoinDomain() call. Or you have to use it in _AD_Open()

  • After _AD_JoinDomain a reboot of the computer is necessary
  • After _AD_JoinDomain please check the returncode
Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Water, thanks again for your help. You have once again resolved my issue.

I was actually going about the Joining domain in a different way. I tried to do it using a series of send keys. I recorded my steps with the AURecorder. I added the functions from the AD.au3 UDF, though I didn't really feel comfortable with using. After your message, I was convinced that this was the best way, and low and behold the problem has been resolved.

Thank you.

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