experience Posted June 3, 2007 Share Posted June 3, 2007 (edited) Hi, i want to add a new PC to the AD domain and change the PC name. Below is a script i've found on this site and modified - i've tried this on my home pc but nothing happens when i click join- any idea where its gone wrong? expandcollapse popup#include <GuiConstants.au3> GuiCreate("PC to Domain Creator", 386, 218, 490,359) $edt_pc_name = GuiCtrlCreateInput("New PC Name", 16, 25, 169, 21) $edt_uname = GuiCtrlCreateInput("Username", 16, 50, 169, 21) $edt_pw = GuiCtrlCreateInput("Password", 16, 75, 169, 21) $btn_join = GuiCtrlCreateButton("Join Domain", 112, 125, 73, 25) $btn_cancel = GuiCtrlCreateButton("Cancel", 112, 160, 73, 25) $GroupBox1 = GuiCtrlCreateGroup("Current Information", 200, 16, 169, 153) $pc_name = GuiCtrlCreateLabel("", 230, 40, 90, 13) $current_user = GuiCtrlCreateLabel("", 230, 60, 90, 13) $pc_ip = GuiCtrlCreateLabel("", 230, 80, 90, 13) $os_build = GuiCtrlCreateLabel("", 230, 100, 90, 13) $service_pack = GuiCtrlCreateLabel("", 230, 120, 90, 13) $Animate1 = GUICtrlCreateAvi ("shell32.dll",152, 88, 130, 16, 16) GUICtrlSetState($Animate1, 0 ) _UpdateLabels() GuiSetState() While 1 $msg = GuiGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case $msg = $btn_cancel ExitLoop Case $msg = $btn_join $domain = ("MyCompanysDomainName") $pc_name = GUICtrlRead($edt_pc_name) $username = GUICtrlRead($edt_uname) $password = GUICtrlRead($edt_pw) ;edit $cmd below to make sure your command line is passed correctly. $cmd = "netdom.exe " & @ComputerName & " /userd:" & $domain & "\" & $username & " /password:" & $password GUICtrlSetState($Animate1, 1) MsgBox(32,"Info",$cmd) ;RunWait(@ComSpec & " /C " & $cmd,"",@SW_HIDE) GUICtrlSetState($Animate1, 0) Case Else ;;; EndSelect WEnd Exit Func _UpdateLabels();update labels here GUICtrlSetData($pc_name,@ComputerName) GUICtrlSetData($current_user,@UserName) GUICtrlSetData($pc_ip,@IPAddress1) GUICtrlSetData($os_build,@OSVersion) GUICtrlSetData($service_pack,@OSServicePack) EndFunc Edited June 3, 2007 by experience Link to comment Share on other sites More sharing options...
GEOSoft Posted June 3, 2007 Share Posted June 3, 2007 A couple of things could cause problems in that script. a) if you change the computer name and or the user name then the system needs to be restarted. if you did not change anything then 1) Does your MsgBox display the proper string? Yes) uncomment the line (Run) below the MsgBox. No) Edit the $Cmd line as noted in the script. If it still won't run then check that the computer and user names are correct and that the domain actually exists. Hints: I would change the Msg Loop to a Switch instead of the Select Since you are only using 1 GUIConstant why do you want to include the entire GUIConstants file? There are other choices. 1) replace the #include line with Constant $GUI_EVENT_CLOSE = -3 2) delete te #include line and just change the reference to $GUI_EVENT_CLOSE to -3 (my preference) Your Switch should read similar to this but you add in the actual code as required $Msg = GUIGetMsg() Switch $Msg Case $Btn_Cancel, -3 ExitLoop Case $Btn_Join ;;Place the code here Case Else ;; Do nothing EndSwitch George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
duijver Posted June 4, 2007 Share Posted June 4, 2007 Hey Experience, I didn't scan your script, but I have already created a script that does go through the process of joining a machine to the domain. It also creates domain controllers so some of the functionality is overkill, but you should be able to use it to get the code to just do the join. Also, as GeoSoft said, you have to reboot after you change a computer name. It will allow you to change the computer name and join a domain but after the reboot you will have problems since it technically joins the machine with the SID/Computername of the current session/boot.Here is the link, you can do a search as well maybe. AD Domain Creation script.. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now