HaeMHuK Posted January 19, 2011 Share Posted January 19, 2011 I am trying to write script which rename pc and join it to domain. I've found something like I need () but it didn't work as I want. expandcollapse popup#include <GUIConstants.au3> #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 625, 443, 193, 125) Global Const $JOIN_DOMAIN = 1 Global Const $ACCT_CREATE = 2 ;User / Domain Data $strComputer = GUICtrlCreateInput("PCNAME", 88, 56, 217, 21) $strAdminAccount = GUICtrlCreateInput("DOMAIN USERNAME", 88, 86, 217, 21) $strAdminPass = GUICtrlCreateInput("PASSWRD", 88, 116, 217, 21) $jdom = GUICtrlCreateButton("Join", 88, 146, 217, 21) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $msg = GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE ExitLoop case $jdom ;Rename Computer $strComputer1 = GUICtrlRead($strComputer) $objWMIService = ObjGet("winmgmts:\\.\root\cimv2") For $colCompSystems in $objWMIService.InstancesOf("Win32_ComputerSystem") $sReturn = $colCompSystems.Rename($strComputer1) If $sReturn <> 0 Then MsgBox(0,"Fail","Rename failed. Error = " & @error & @CRLF & "Exiting script.") Exit Else MsgBox(0,"Rename","Rename successful.") EndIf Next ;Join to Domain $strAdminAccount1 = GUICtrlRead($strAdminAccount) $strAdminPass1 = GUICtrlRead($strAdminPass) $strDomainName = "DOMAIN.COM" $strComputer1 = GUICtrlRead($strComputer) $objWMIService = ObjGet("winmgmts:" & "{impersonationLevel=impersonate}!\\" & $strComputer1 & "\root\cimv2") $colCompSystems = $objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystem") For $objCompSystem In $colCompSystems MsgBox(0, 'Joining Domain', "Computer Name: " & $objCompSystem.Name & @CRLF & @CRLF & "Domain - Before: " & $objCompSystem.Domain) $intJoinDomain = $objCompSystem.JoinDomainOrWorkgroup($strDomainName, $strAdminPass1, $strDomainName & '\' & $strAdminAccount1, '', $JOIN_DOMAIN + $ACCT_CREATE) If $intJoinDomain = 0 Then MsgBox(0, @ScriptName, "Joined computer to " & $strDomainName & " domain.") ElseIf $intJoinDomain = 1 Then MsgBox(0, @ScriptName, "Joined computer to " & $strDomainName & " domain." & @CRLF & " Must reboot.") Else EndIf Next EndSwitch WEnd This script doesn't join pc to domain because it doesn't recognize new pc name before restarting. So if the pc wasn't restarted I couldn't join to domain with new name. Please, help me to reedit it. Link to comment Share on other sites More sharing options...
water Posted January 19, 2011 Share Posted January 19, 2011 You have to reboot after renaming the computer and after joining the computer to the domain as well. My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.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 (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 More sharing options...
HaeMHuK Posted January 19, 2011 Author Share Posted January 19, 2011 (edited) Yes, I know it. But If I use Windows Wizard (Computer properties - Network ID - ...) all this things could be done in one action. I mean I don't need to restart PC after renaming to join it to domain. Edited January 19, 2011 by HaeMHuK Link to comment Share on other sites More sharing options...
kor Posted January 19, 2011 Share Posted January 19, 2011 Yes, I know it. But If I use Windows Wizard (Computer properties - Network ID - ...) all this actions could be done in one action.No. It can't.I mean I don't need to restart PC after renaming to join it to domain.Yes you do.I went over and over this about a year ago trying to do the same thing and the only method I could get to join a domain successfully and reliably with the new computer name was to reboot it before joining to the domain. Link to comment Share on other sites More sharing options...
HaeMHuK Posted January 19, 2011 Author Share Posted January 19, 2011 No. It can't.Yes you do.I went over and over this about a year ago trying to do the same thing and the only method I could get to join a domain successfully and reliably with the new computer name was to reboot it before joining to the domain.Well, I've tried to add PC to domain through the Network ID. It changed PC name and joined it to domain and only after this two actions I had rebooted PC. Like here: http://www.wpi.edu/academics/CCC/Help/Network/Setup/winxp.html Link to comment Share on other sites More sharing options...
ShawnW Posted January 19, 2011 Share Posted January 19, 2011 Kor you are wrong, I don't know about that program but I have a script somewhere that can rename and join the domain with the new name all without restarting. I've used it in production and it works fine. I'll try and dig it out. Link to comment Share on other sites More sharing options...
kor Posted January 19, 2011 Share Posted January 19, 2011 (edited) Kor you are wrong, I don't know about that program but I have a script somewhere that can rename and join the domain with the new name all without restarting. I've used it in production and it works fine. I'll try and dig it out.For what OS? I've never been able to get an XP machine to RELIABLY rename and join a domain without a restart in between. Edited January 19, 2011 by kor Link to comment Share on other sites More sharing options...
iamtheky Posted January 19, 2011 Share Posted January 19, 2011 I have this one from skinny white guy, I didnt use the domain stuff (though it remains, just commented out), but the name changing works on the fly. expandcollapse popup;==================================================================================== ; Fix Computer Name & Workgroup Name Script ; by: tHe SkInNy WhItE GuY ; 03-06-2007 ;==================================================================================== ; Initialize Settings #include <GUIConstants.au3> #NoTrayIcon #include <Constants.au3> Global $OldName = @ComputerName ; Initialize Variables Needed Dim $CompName, $Workgroup, $dir_create ; Build Forms to ask User for New Name and Workgroup Selection Box Opt("GUIOnEventMode", 1) $mainwindow = GUICreate("Name Changer", 200, 120) GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked") GUICtrlCreateLabel("Enter the Name and workgroup to set on this computer", 10, 10, 180, 30) GUICtrlCreateLabel("Name", 10, 40, 70, 20) ;~ GUICtrlCreateLabel("Workgroup", 10, 60, 70, 20) $inp_name = GUICtrlCreateInput("", 80, 40, 100, 20) ;~ $inp_group = GUICtrlCreateInput("", 80, 60, 100, 20) $set = GUICtrlCreateButton("Set", 70, 90, 60) GUICtrlSetOnEvent($set, "Set_Names") GUISetState(@SW_SHOW) While 1 Sleep(1000) ; Idle around WEnd Func Set_Names() ; Name & Workgroup Name $CompName = GUICtrlRead($inp_name, 1) ;~ $Workgroup = GUICtrlRead($inp_group, 1) GUICtrlSetState($inp_name, $GUI_DISABLE) ;~ GUICtrlSetState($inp_group, $GUI_DISABLE) GUICtrlSetData($set, "Updating...") GUICtrlSetState($set, $GUI_DISABLE) ; Install needed files onto the computer ;~ FileInstall ("NetDom.exe", @TempDir & "NetDom.exe", 1) ; Make some registry changes to also change the Name now 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) ; change Workgroup with Netdom.exe ;~ RunWait (@TempDir & "Netdom.exe Member \\" & $CompName & " /JOINWorkgroup " & $Workgroup, "", @SW_HIDE) ; Remove needed files ;~ FileDelete (@TempDir & "NetDom.exe") MsgBox(0, "Done", "Computer was renamed from " & $OldName & "to " & $CompName & ".") ;~ GUICtrlSetState($inp_name, $GUI_ENABLE) ;~ GUICtrlSetState($inp_group, $GUI_ENABLE) ;~ GUICtrlSetData($set, "Set") ;~ GUICtrlSetState($set, $GUI_ENABLE) EndFunc ;==>Set_Names Func CLOSEClicked() run ("shutdown -r -t 0") Exit EndFunc ;==>CLOSEClicked ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
ShawnW Posted January 19, 2011 Share Posted January 19, 2011 (edited) Well I didn't wanna dig through a huge script to see what we used in production but I believe I used this in testing. I didn't really have that many variables since a lot of it was just put inline. I pulled it out to make it easier to edit. #include "EnvUpdate.au3" $CompName = 'BA-Test' $ou = 'ou=*****,ou="**** *******",ou=***,dc=***,dc=**,dc=***,dc=***' $fulldomain = '***.**.***.***' $domain = '***' $user = '***********' $password = '***********' ; http://msdn.microsoft.com/en-us/library/ms724931(v=VS.85).aspx ; Parameter int 5 = ComputerNamePhysicalDnsHostname $result = DllCall("Kernel32.dll", "BOOL", "SetComputerNameEx", "int", 5, "str", $CompName) If $result[0] = 0 Then MsgBox(0, "Error: Kernel32.dll", "SetComputerNameEx() Failed. Return code: " & $result[0]) RegWrite("HKLM\SYSTEM\CurrentControlSet\Control\Computername\ActiveComputername", "ComputerName", "REG_SZ", $CompName) RegWrite("HKLM\SYSTEM\CurrentControlSet\Control\Computername\Computername", "ComputerName", "REG_SZ", $CompName) RegWrite("HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters", "Hostname", "REG_SZ", $CompName) RegWrite("HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters", "NV Hostname", "REG_SZ", $CompName) RegWrite("HKEY_USERS\.Default\Software\Microsoft\Windows Media\WMSDK\General", "Computername", "REG_SZ", $CompName) _EnvUpdate("COMPUTERNAME", $CompName, False, True) ; http://msdn.microsoft.com/en-us/library/aa370433(VS.85).aspx $result = DllCall("Netapi32.dll", "long", "NetJoinDomain", "int", 0, "wstr", $fulldomain, "wstr", $ou, "wstr", $domain & "\" & $user, "wstr", $password, "dword", 0x00000423) MsgBox(0, "1", "Return: " & $result[0] & @CRLF & "Error code: " & @error) ; If Dll returned anything but 0 then it failed Try again without creating an object in case it failed because the object already existed. If $result[0] Then $result = DllCall("Netapi32.dll", "long", "NetJoinDomain", "int", 0, "wstr", $fulldomain, "wstr", $ou, "wstr", $domain & "\" & $user, "wstr", $password, "dword", 0x00000421) MsgBox(0, "2", "Return: " & $result[0] & @CRLF & "Error code: " & @error) EndIf RegWrite("HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon", "AltDefaultDomainName", "REG_SZ", $domain) RegWrite("HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon", "DefaultDomainName", "REG_SZ", $domain) And the EnvUpdate.au3 I found somewhere here on the forums but here it is so you don't have to search. expandcollapse popup#include-once ; #INDEX# ======================================================================================================================= ; Title .........: Environment Update ; AutoIt Version.: 3.2.12++ ; Language.......: English ; Description ...: Refreshes the OS environment. ; Author ........: João Carlos (jscript) ; Support .......: trancexx, PsaltyDS, KaFu ; =============================================================================================================================== ; #CURRENT# ===================================================================================================================== ;_EnvUpdate ; =============================================================================================================================== ; #INTERNAL_USE_ONLY# =========================================================================================================== ; =============================================================================================================================== ; #VARIABLES# =================================================================================================================== Global $MAX_VALUE_NAME = 1024 Global $HWND_BROADCAST = 0xffff Global $WM_SETTINGCHANGE = 0x001A Global $SMTO_ABORTIFHUNG = 0x0002 Global $SMTO_NORMAL = 0x0000 Global $MSG_TIMEOUT = 5000 ; #Example# ===================================================================================================================== ;_EnvUpdate("VERSION", "7.07.0110.2600") ;MsgBox(4096, @error, EnvGet("VERSION")) ;_EnvUpdate("VERSION", "", True, True) ;MsgBox(4096, @error, EnvGet("VERSION")) ; =============================================================================================================================== ; #FUNCTION# ==================================================================================================================== ; Name...........: _EnvUpdate ; Description ...: Refreshes the OS environment. ; Syntax.........: _EnvUpdate( ["envvariable" [, "value" [, CurrentUser [, Machine ]]]] ) ; Parameters ....: envvariable - [optional] Name of the environment variable to set. If no variable, refreshes all variables. ; value - [optional] Value to set the environment variable to. If a value is not used the environment ; variable will be deleted. ; CurrentUser - [optional] Sets the variable in current user environment. ; Machine - [optional] Sets the variable in the machine environment. ; Return values .: Success - None ; Failure - Sets @error to 1. ; Author ........: João Carlos (jscript) ; Support .......: trancexx, PsaltyDS, KaFu ; Modified.......: ; Remarks .......: ; Related .......: ; Link ..........; ; Example .......; _EnvUpdate("TEMP", @SystemDir & "TEMP", True, True) ; =============================================================================================================================== Func _EnvUpdate($sEnvVar = "", $vValue = "", $fCurrentUser = True, $fMachine = False) Local $sREG_TYPE = "REG_SZ", $iRet1, $iRet2 If $sEnvVar <> "" Then If StringInStr($sEnvVar, "\") Then $sREG_TYPE = "REG_EXPAND_SZ" If $vValue <> "" Then If $fCurrentUser Then RegWrite("HKCU\Environment", $sEnvVar, $sREG_TYPE, $vValue) If $fMachine Then RegWrite("HKLM\System\CurrentControlSet\Control\Session Manager\Environment", $sEnvVar, $sREG_TYPE, $vValue) Else If $fCurrentUser Then RegDelete("HKCU\Environment", $sEnvVar) If $fMachine Then RegDelete("HKLM\System\CurrentControlSet\Control\Session Manager\Environment", $sEnvVar) EndIf ; http://msdn.microsoft.com/en-us/library/ms686206%28VS.85%29.aspx $iRet1 = DllCall("Kernel32.dll", "BOOL", "SetEnvironmentVariable", "str", $sEnvVar, "str", $vValue) If $iRet1[0] = 0 Then Return SetError(1) EndIf ; http://msdn.microsoft.com/en-us/library/ms644952%28VS.85%29.aspx $iRet2 = DllCall("user32.dll", "lresult", "SendMessageTimeoutW", _ "hwnd", $HWND_BROADCAST, _ "dword", $WM_SETTINGCHANGE, _ "ptr", 0, _ "wstr", "Environment", _ "dword", $SMTO_ABORTIFHUNG, _ "dword", $MSG_TIMEOUT, _ "dword_ptr*", 0) If $iRet2[0] = 0 Then Return SetError(1) EndFunc ;==>_EnvUpdate Edit: And this was used and tested on XP only. Edited January 19, 2011 by ShawnW Link to comment Share on other sites More sharing options...
HaeMHuK Posted January 20, 2011 Author Share Posted January 20, 2011 ShawnWThanks a lot. It works perfect. Link to comment Share on other sites More sharing options...
iGoLike Posted July 25, 2013 Share Posted July 25, 2013 Hi, This is a old thread but it correspond well with my problem. When i try to use your solution ShawnW i get an error: ...EnvUpdate.au3 (21) : ==> Can not redeclare a constant.: Global $WM_SETTINGCHANGE = 0x001A Global ^ ERROR Is there anyway to solve this? '?do=embed' frameborder='0' data-embedContent>> I use Windows 7, and have tryed on Win XP too, but it gives the same result. So that´s not the case. Link to comment Share on other sites More sharing options...
KaFu Posted July 25, 2013 Share Posted July 25, 2013 That means an underlying include-file has been changed and the wm_settingchange constant already exists. Just comment the line out in the custom include, changeGlobal $WM_SETTINGCHANGE = 0x001Ato; Global $WM_SETTINGCHANGE = 0x001A OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2024-Oct-20) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
iGoLike Posted July 25, 2013 Share Posted July 25, 2013 Thanks for your response KaFu! I did as you asked, Global $WM_SETTINGCHANGE = 0x001A and "dword", $WM_SETTINGCHANGE, _ are both commented. But in result I did get a new error massage: Error parsing function call. I guess that´s because the DLLCall is missing an argument. I looked up DLLCall and all it´s arguments are optional, so it should not complain? I hope you could help me some more here to find a solution =P Link to comment Share on other sites More sharing options...
iGoLike Posted July 31, 2013 Share Posted July 31, 2013 Solved. I have been here for 3 weeks, must say it´s a great community. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted July 31, 2013 Moderators Share Posted July 31, 2013 iGoLike,Delighted to hear that you enjoy the forum. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
tbwalker Posted September 19, 2013 Share Posted September 19, 2013 Thanks for your response KaFu! I did as you asked, Global $WM_SETTINGCHANGE = 0x001A and "dword", $WM_SETTINGCHANGE, _ are both commented. But in result I did get a new error massage: Error parsing function call. I guess that´s because the DLLCall is missing an argument. I looked up DLLCall and all it´s arguments are optional, so it should not complain? I hope you could help me some more here to find a solution =P Solved. I have been here for 3 weeks, must say it´s a great community. IGoLike, how did you solve your problem of "Error parsing function call" ? I'd like to use the script as well, but I'd like to avoid any errors if possible. Thanks. Link to comment Share on other sites More sharing options...
antonioj84 Posted April 3, 2017 Share Posted April 3, 2017 On 31/07/2013 at 4:41 AM, iGoLike said: Solved. I have been here for 3 weeks, must say it´s a great community. well about posting your example, realize the thread is 4years old. i have the exact same problem rename PC and addo workgroup on the fly (no reboot required) Link to comment Share on other sites More sharing options...
antonioj84 Posted April 3, 2017 Share Posted April 3, 2017 On 19/01/2011 at 7:01 AM, HaeMHuK said: I am trying to write script which rename pc and join it to domain. I've found something like I need ( ) but it didn't work as I want. expandcollapse popup#include <GUIConstants.au3> #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 625, 443, 193, 125) Global Const $JOIN_DOMAIN = 1 Global Const $ACCT_CREATE = 2 ;User / Domain Data $strComputer = GUICtrlCreateInput("PCNAME", 88, 56, 217, 21) $strAdminAccount = GUICtrlCreateInput("DOMAIN USERNAME", 88, 86, 217, 21) $strAdminPass = GUICtrlCreateInput("PASSWRD", 88, 116, 217, 21) $jdom = GUICtrlCreateButton("Join", 88, 146, 217, 21) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $msg = GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE ExitLoop case $jdom ;Rename Computer $strComputer1 = GUICtrlRead($strComputer) $objWMIService = ObjGet("winmgmts:\\.\root\cimv2") For $colCompSystems in $objWMIService.InstancesOf("Win32_ComputerSystem") $sReturn = $colCompSystems.Rename($strComputer1) If $sReturn <> 0 Then MsgBox(0,"Fail","Rename failed. Error = " & @error & @CRLF & "Exiting script.") Exit Else MsgBox(0,"Rename","Rename successful.") EndIf Next ;Join to Domain $strAdminAccount1 = GUICtrlRead($strAdminAccount) $strAdminPass1 = GUICtrlRead($strAdminPass) $strDomainName = "DOMAIN.COM" $strComputer1 = GUICtrlRead($strComputer) $objWMIService = ObjGet("winmgmts:" & "{impersonationLevel=impersonate}!\\" & $strComputer1 & "\root\cimv2") $colCompSystems = $objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystem") For $objCompSystem In $colCompSystems MsgBox(0, 'Joining Domain', "Computer Name: " & $objCompSystem.Name & @CRLF & @CRLF & "Domain - Before: " & $objCompSystem.Domain) $intJoinDomain = $objCompSystem.JoinDomainOrWorkgroup($strDomainName, $strAdminPass1, $strDomainName & '\' & $strAdminAccount1, '', $JOIN_DOMAIN + $ACCT_CREATE) If $intJoinDomain = 0 Then MsgBox(0, @ScriptName, "Joined computer to " & $strDomainName & " domain.") ElseIf $intJoinDomain = 1 Then MsgBox(0, @ScriptName, "Joined computer to " & $strDomainName & " domain." & @CRLF & " Must reboot.") Else EndIf Next EndSwitch WEnd This script doesn't join pc to domain because it doesn't recognize new pc name before restarting. So if the pc wasn't restarted I couldn't join to domain with new name. Please, help me to reedit it. This a very good example, i was hopeful that i can solve immediately, however i have 2 questions: 1. can someone point me where I can download netdom.exe 2. can netdom.exe be used with windows 10 Link to comment Share on other sites More sharing options...
Subz Posted April 3, 2017 Share Posted April 3, 2017 RSAT includes NetDomhttps://support.microsoft.com/en-us/help/2693643/remote-server-administration-tools-rsat-for-windows-operating-systems Although you can now use PowerShell to add a machine to the domain: Add-Computer –DomainName Domain.local –Credential (Get-Credential)https://msdn.microsoft.com/en-us/powershell/reference/5.1/microsoft.powershell.management/add-computer antonioj84 1 Link to comment Share on other sites More sharing options...
antonioj84 Posted April 3, 2017 Share Posted April 3, 2017 Fantastic. actually, i am joining a workgroup, thanks to your link i was able to download netdom.exe, however with PowerShell how would i call that function in autoit, is that possible with PowerShellPowershell Script to Rename Computer without Reboot $ComputerName = "New Name" Remove-ItemProperty -path "HKLM:\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters" -name "Hostname" Remove-ItemProperty -path "HKLM:\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters" -name "NV Hostname" New-PSDrive -name HKU -PSProvider "Registry" -Root "HKEY_USERS" Set-ItemProperty -path "HKLM:\SYSTEM\CurrentControlSet\Control\Computername\Computername" -name "Computername" -value $ComputerName Set-ItemProperty -path "HKLM:\SYSTEM\CurrentControlSet\Control\Computername\ActiveComputername" -name "Computername" -value $ComputerName Set-ItemProperty -path "HKLM:\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters" -name "Hostname" -value $ComputerName Set-ItemProperty -path "HKLM:\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters" -name "NV Hostname" -value $ComputerName Set-ItemProperty -path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" -name "AltDefaultDomainName" -value $ComputerName Set-ItemProperty -path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" -name "DefaultDomainName" -value $ComputerName #Set-ItemProperty -path "HKU:\.Default\Software\Microsoft\Windows Media\WMSDK\General" -name "Computername" -value $ComputerName PS C:\> Add-Computer -WorkGroupName "WORKGROUP-A" thanks 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