Jump to content
Sign in to follow this  
inferno123

AD access on local account

Recommended Posts

I am trying to search for computers in AD while being logged locally and computer is not a domain memeber. Please tell if that can be done

Script work when I am logged on domain account. The thing is that it must work on local account. Please help

That is my code.

CODE
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****

#AutoIt3Wrapper_icon=..\..\..\My Documents\Icons\Connect.ico

#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

#include <GuiConstants.au3>

#include <Array.au3>

#Include <_XMLDomWrapper.au3>

#include <XML_Functions.au3>

#region --- GuiBuilder code Start ---

#include <GuiConstants.au3>

Global $adminuser, $inp_password, $ping, $CompName, $inp_computer_name,$inp_adminuser

Global $objConnection = ObjCreate("ADODB.Connection")

Global $objCommand = ObjCreate("ADODB.Command"); Create COM object to AD

Global $objRootDSE = ObjGet("LDAP://RootDSE")

Global $strDNSDomain = $objRootDSE.Get ("defaultNamingContext") ; Retrieve the current AD domain name

Global $strHostServer = $objRootDSE.Get ("dnsHostName") ; Retrieve the name of the connected DC

Global $strConfiguration = $objRootDSE.Get ("ConfigurationNamingContext") ; Retrieve the Configuration naming context

$Gui_Main = GUICreate("Name Changer and Domain Join", 392, 323, -1, -1, BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS))

Opt("GUIOnEventMode", 1)

GUISetOnEvent($GUI_EVENT_CLOSE, "_GuiCloseClick")

$button_2 = GUICtrlCreateButton("Set", 285, 40, 80, 40)

$Group_1 = GUICtrlCreateGroup("", 10, 10, 370, 300)

$Label_2 = GUICtrlCreateLabel("User Name", 40, 45, 80, 20)

$Label_3 = GUICtrlCreateLabel("Password", 50, 90, 120, 40)

$Label_4 = GUICtrlCreateLabel("Domain", 50, 140, 120, 50)

$Label_5 = GUICtrlCreateLabel("Computer Name", 30, 185, 120, 30)

$inp_computer_name = GUICtrlCreateInput("XFLTEST30636", 120, 185, 150, 20)

$inp_adminuser = GUICtrlCreateCombo("", 120, 30, 150, 21)

$inp_password = GUICtrlCreateInput("", 120, 90, 150, 20, 0x20)

$Button_1 = GUICtrlCreateButton("Start", 90, 240, 210, 40)

$Button_3 = GUICtrlCreateButton("Verify Availability", 280, 185, 90, 20)

$inp_domain = GUICtrlCreateInput("EMA.LILLY.COM", 120, 140, 150, 20)

GUISetState()

GUICtrlSetOnEvent($Button_1, "Main")

GUICtrlSetOnEvent($button_2, "_ButtonOne")

GUICtrlSetOnEvent($Button_3, "Computer_in_AD")

_CheckLogins()

While 1

Sleep(1)

WEnd

Func Main()

$CompName = GUICtrlRead($inp_computer_name, 1)

$Domain = GUICtrlRead($inp_domain, 1)

$adminuser = GUICtrlRead($inp_adminuser, 1)

$password = GUICtrlRead($inp_password, 1)

GUICtrlSetState($inp_computer_name, $GUI_DISABLE)

GUICtrlSetState($inp_domain, $GUI_DISABLE)

GUICtrlSetState($inp_adminuser, $GUI_DISABLE)

GUICtrlSetState($inp_password, $GUI_DISABLE)

GUICtrlSetData($Button_1, "Updating...")

GUICtrlSetState($Button_1, $GUI_DISABLE)

FileInstall("C:\Documents and Settings\ypx8157\Desktop\Scripts\Name Changer and Domain Join\NetDom.exe", @TempDir & "\NetDom.exe", 1)

; registry changes to change the computer name

RegDelete("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters", "Hostname")

RegDelete("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters", "NV Hostname")

RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Computername\Computername", "Computername", "REG_SZ", $CompName)

RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Computername\ActiveComputername", "Computername", "REG_SZ", $CompName)

RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters", "Hostname", "REG_SZ", $CompName)

RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters", "NV Hostname", "REG_SZ", $CompName)

RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon", "AltDefaultDomainName", "REG_SZ", $CompName)

RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon", "DefaultDomainName", "REG_SZ", $CompName)

RegWrite("HKEY_USERS\.Default\Software\Microsoft\Windows Media\WMSDK\General", "Computername", "REG_SZ", $CompName)

MsgBox(0, "", "Now this computer will begin the domain join process. Make sure that you have connection to local Domain Controller")

Dim $DC_array[1]

$settings_install = @ScriptDir & "\Config.xml"

If IsArray(_MyXMLReadNodes ($settings_install, "settings", "basic_configuration/DC_List")) Then

$DC_array_temp = _MyXMLReadNodes ($settings_install, "settings", "basic_configuration/DC_List")

For $a = 1 To $DC_array_temp [0]

_ArrayAdd($DC_array, (_MyXMLRead ($settings_install, "settings", "basic_configuration/DC_List/" & $DC_array_temp[$a])))

Next

Else

MsgBox(0, "", @error)

EndIf

$ping_1 = Ping($DC_array[1])

$ping_2 = Ping($DC_array[2])

$ping_3 = Ping($DC_array[3])

$ping_4 = Ping($DC_array[4])

$ping_5 = Ping($DC_array[5])

$ping_6 = Ping($DC_array[6])

$ping_7 = Ping($DC_array[7])

$ping_8 = Ping($DC_array[8])

$ping_9 = Ping($DC_array[9])

$ping_10 = Ping($DC_array[10])

If $ping_1 Or $ping_2 Or $ping_3 Or $ping_4 Or $ping_5 Or $ping_6 Or $ping_7 Or $ping_8 Or $ping_9 Or $ping_10 > 0 Then

;Change Domain with Netdom.exe

$path_to_netdom = @TempDir & "\Netdom.exe"

RunWait(@ComSpec & " /c " & $path_to_netdom & " join /d:" & $Domain & " " & $CompName & " /userd:" & $adminuser & " /passwordd:" & $password & " /verbose", "", @SW_SHOW)

RunWait(@ComSpec & " /c " & "net stop netlogon && net start netlogon")

RunWait(@ComSpec & " /c " & "net stop w32time && net start w32time")

RunWait(@ComSpec & " /c " & "w32tm /resync")

MsgBox(0, "Done", "Computer was renamed to """ & $CompName & """ and Domain was set to """ & $Domain & """.")

$message = MsgBox(16, "Computer Restart", "You must restart this computer for the changes to take effect.")

If $message = 1 Then

Shutdown(2)

EndIf

If $message = 2 Then

_GuiCloseClick()

EndIf

Else

MsgBox(16, "Connection Error", "No connection with Domain Conrtoller detected")

Exit

EndIf

; Remove needed files

FileDelete(@TempDir & "\NetDom.exe")

GUICtrlSetState($inp_adminuser, $GUI_ENABLE)

GUICtrlSetState($inp_password, $GUI_ENABLE)

GUICtrlSetState($inp_computer_name, $GUI_ENABLE)

GUICtrlSetState($inp_domain, $GUI_ENABLE)

GUICtrlSetData($Button_1, "Set")

GUICtrlSetState($Button_1, $GUI_ENABLE)

EndFunc ;==>Main

Func _ADOComputerExists($object)

$strQuery = "<LDAP://" & $strHostServer & "/" & $strDNSDomain & ">;(&(objectCategory=computer)(name="& $object &"));Name;subtree"

$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 ;==>_

Func Computer_in_AD()

$adminuser = GUICtrlRead($inp_adminuser, 1)

$password = GUICtrlRead($inp_password, 1)

$objConnection = ObjCreate("ADODB.Connection")

$objConnection.Provider = "ADsDSOObject"

$objConnection.Properties("User ID") = $inp_adminuser

$objConnection.Properties("Password") = $inp_password

$objConnection.Properties("Encrypt Password") = False

$objConnection.Properties("ADSI Flag") = 1

$objConnection.Open ("Active Directory Provider")

$CompName = GUICtrlRead($inp_computer_name, 1)

$check = _ADOComputerExists ($CompName)

$ping_comp = Ping($CompName)

If $check = 1 And $ping_comp = 0 Then

MsgBox(16, "", "Computer Name exists in Active Directory and can be assigned to this computer!!!")

GUICtrlSetState($Button_1, $GUI_ENABLE)

ElseIf $check = 1 And $ping_comp > 0 Then

MsgBox(16, "", "Computer Name exists in Active Directory, however it has already been assigned to a computer. Choose another name for this computer!!!")

GUICtrlSetState($Button_1, $GUI_DISABLE)

ElseIf $check = 0 Then

MsgBox(16, "", "Computer Name does not exist in Active Directory. Either choose a different computer name or add a new computer to Active Directory")

GUICtrlSetState($Button_1, $GUI_DISABLE)

EndIf

EndFunc ;==>Computer_in_AD

Func _ButtonOne()

If GUICtrlGetState($inp_adminuser) = 80 Then

If GUICtrlRead($inp_adminuser) = "" Or GUICtrlRead($inp_adminuser) = "Domain\UserID" Or GUICtrlRead($inp_password) = "" Then

MsgBox(16, "Error", "Bad settings for domain\username or password")

Else

$UserName1 = GUICtrlRead($inp_adminuser, 1)

$Pwd = GUICtrlRead($inp_password, 1)

GUICtrlSetState($inp_adminuser, $GUI_DISABLE)

GUICtrlSetState($inp_password, $GUI_DISABLE)

GUICtrlSetData($button_2, "Unset")

EndIf

Else

GUICtrlSetState($inp_adminuser, $GUI_ENABLE)

GUICtrlSetState($inp_password, $GUI_ENABLE)

GUICtrlSetData($button_2, "Set")

EndIf

EndFunc ;==>_ButtonOne

Func _CheckLogins()

$settings_install = @ScriptDir & "\Config.xml"

If IsArray(_MyXMLReadNodes ($settings_install, "settings", "basic_configuration/domain_accounts")) Then

$domain_accounts = _MyXMLReadNodes ($settings_install, "settings", "basic_configuration/domain_accounts")

If $domain_accounts[0] = 1 Then ; If only one username fills in directly in input box

GUICtrlSetData($inp_adminuser, _MyXMLRead ($settings_install, "settings", "basic_configuration/domain_accounts/" & $domain_accounts[1]))

Else ; Creates combo box to choose from list or input yourname yourself

GUICtrlDelete($inp_adminuser)

$inp_adminuser = GUICtrlCreateCombo("", 120, 40, 150, 21)

For $a = 1 To $domain_accounts[0]

GUICtrlSetData($inp_adminuser, _MyXMLRead ($settings_install, "settings", "basic_configuration/domain_accounts/" & $domain_accounts[$a]))

Next

EndIf

EndIf

EndFunc ;==>_CheckLogins

Func _GuiCloseClick()

If @GUI_WinHandle = $Gui_Main Then

Exit

EndIf

EndFunc ;==>_GuiCloseClick

Edited by inferno123

Share this post


Link to post
Share on other sites

I dont know if this helps you, but i have allways found php ldap script's as a somewhat guide, since they have pretty much the same as AutoIt script's and rewriting them aint to hard. And they are easy to find on the net.


UDF:Crypter a file encrypt / decrypt tool with no need to remember a password again. Based on Caesar cipher using entire ASCII Table.Script's: PixelSearch Helper, quick and simple way to create a PixelSeach.Chatserver - simplified, not so complicated multi-socket server.AutoIT - Firewall, simple example on howto create a firewall with AutoIt.

Share this post


Link to post
Share on other sites

Thank you. I found a script however I do not know what the ldap_connect( $ldap_host, $ldap_port) procedure does. If anybody could give soem clues how to reproduce ldap_connect from PHP. Thank you in advance

if ($name_submitted != "" && $passwd_submitted != "") {

$ldap_host = "ldap://someserver.rhodes.edu";

$base_dn = "CN=Users,DC=rhodes, DC=edu";

if ($search_submitted == "") {

$search_value = $name_submitted;

} else {

$search_value = $search_submitted;

}

$filter = "(CN=$search_value)";

$ldap_user = "CN=$name_submitted, CN=Users, DC=rhodes, DC=edu";

$ldap_pass = $passwd_submitted;

$connect = ldap_connect( $ldap_host, $ldap_port)

or exit("Could not connect to LDAP server");

// required to search AD, according to note in PHP manual notes

ldap_set_option($connect, LDAP_OPT_PROTOCOL_VERSION, 3);

ldap_set_option($connect, LDAP_OPT_REFERRALS, 0);

$bind = ldap_bind($connect, $ldap_user, $ldap_pass)

or exit("Could not bind to $ldap_host");

echo "Successful bind to $ldap_host with $bind<br><br>\n";

$read = ldap_search($connect, $base_dn, $filter)

or exit("Unable to search ldap server");

$info = ldap_get_entries($connect, $read);

echo $info["count"]." entries returned for $filter<br><br>\n";

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  

×
×
  • Create New...