Subz Posted April 3, 2017 Share Posted April 3, 2017 (edited) Untested, you will need to un-comment all the lines that are commented, didn't want anyone inadvertently running the code, personally I would force reboot but you can give it a try without rebooting: #RequireAdmin #include <WinAPIFiles.au3> Local $sComputerName = "New Name" Local $sWorkGroup = "WORKGROUP-A" Local $sHKLMRoot If @OSArch = "x64" Then $sHKLMRoot = "HKLM64" Else $sHKLMRoot = "HKLM" EndIf Local $idMsgBox = MsgBox(49, "Computer Rename", "Rename Computer to: " & $sComputerName & @CRLF & "Join WorkGroup: " & $sWorkGroup & @CRLF & "Do you wish to continue?") If $idMsgBox = 6 Then ;~ RegDelete($sHKLMRoot & "\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters", "Hostname") ;~ RegDelete($sHKLMRoot & "\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters", "NV Hostname") ;~ RegWrite($sHKLMRoot & "\SYSTEM\CurrentControlSet\Control\Computername\Computername", "Computername", "REG_SZ", $sComputerName) ;~ RegWrite($sHKLMRoot & "\SYSTEM\CurrentControlSet\Control\Computername\ActiveComputername", "Computername", "REG_SZ", $sComputerName) ;~ RegWrite($sHKLMRoot & "\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters", "Hostname", "REG_SZ", $sComputerName) ;~ RegWrite($sHKLMRoot & "\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters", "NV Hostname", "REG_SZ", $sComputerName) ;~ RegWrite($sHKLMRoot & "\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon", "AltDefaultDomainName", "REG_SZ", $sComputerName) ;~ RegWrite($sHKLMRoot & "\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon", "DefaultDomainName", "REG_SZ", $sComputerName) If @OSArch = "x64" Then DllCall("kernel32.dll", "boolean", "Wow64DisableWow64FsRedirection", "boolean", 1) ;~ Turns On 64 Bit Redirection ;~ RunWait('PowerShell.exe -Command "& {Add-Computer -WorkGroupName }"') DllCall("kernel32.dll", "boolean", "Wow64DisableWow64FsRedirection", "boolean", 0) ;~ Turns Off 64 Bit Redirection Else ;~ RunWait('PowerShell.exe -Command "& {Add-Computer -WorkGroupName }"') EndIf EndIf Edited April 3, 2017 by Subz antonioj84 1 Link to comment Share on other sites More sharing options...
antonioj84 Posted April 3, 2017 Share Posted April 3, 2017 (edited) Edited April 3, 2017 by antonioj84 wrong Link to comment Share on other sites More sharing options...
antonioj84 Posted April 3, 2017 Share Posted April 3, 2017 (edited) ok Edited April 3, 2017 by antonioj84 wrong Link to comment Share on other sites More sharing options...
antonioj84 Posted April 3, 2017 Share Posted April 3, 2017 well this one work like a charm on first try no reboot required, can you improve on it ? #RequireAdmin #include <WinAPIFiles.au3> Local $sComputerName = "Lenovo-PC1" Local $sWorkGroup = "WORKGROUP1" Local $sDescription ="Lenovo-PC1" Rename($sComputerName) Func Rename($name) RegWrite("HKLM\SYSTEM\CurrentControlSet\Control\ComputerName\ActiveComputerName", "ComputerName","REG_SZ", $name) RegWrite("HKLM\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName", "ComputerName", "REG_SZ", $name) RegWrite("HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters", "Hostname", "REG_SZ", $name) RegWrite("HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters", "NV Hostname", "REG_SZ", $name) Return 0 EndFunc Link to comment Share on other sites More sharing options...
antonioj84 Posted April 3, 2017 Share Posted April 3, 2017 #RequireAdmin #include <WinAPIFiles.au3> Local $sComputerName = "New Name" Local $sWorkGroup = "WORKGROUP-A" Local $sHKLMRoot If @OSArch = "x64" Then $sHKLMRoot = "HKLM64" Else $sHKLMRoot = "HKLM" EndIf Local $idMsgBox = MsgBox(49, "Computer Rename", "Rename Computer to: " & $sComputerName & @CRLF & "Join WorkGroup: " & $sWorkGroup & @CRLF & "Do you wish to continue?") If $idMsgBox = 6 Then ;~ RegDelete($sHKLMRoot & "\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters", "Hostname") ;~ RegDelete($sHKLMRoot & "\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters", "NV Hostname") RegWrite($sHKLMRoot & "\SYSTEM\CurrentControlSet\Control\Computername\Computername", "Computername", "REG_SZ", $sComputerName) RegWrite($sHKLMRoot & "\SYSTEM\CurrentControlSet\Control\Computername\ActiveComputername", "Computername", "REG_SZ", $sComputerName) RegWrite($sHKLMRoot & "\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters", "Hostname", "REG_SZ", $sComputerName) RegWrite($sHKLMRoot & "\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters", "NV Hostname", "REG_SZ", $sComputerName) RegWrite($sHKLMRoot & "\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon", "AltDefaultDomainName", "REG_SZ", $sWorkGroup ) workgroup RegWrite($sHKLMRoot & "\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon", "DefaultDomainName", "REG_SZ", $sWorkGroup ) ; workgroup ;~ If @OSArch = "x64" Then ;~ DllCall("kernel32.dll", "boolean", "Wow64DisableWow64FsRedirection", "boolean", 1) ;~ Turns On 64 Bit Redirection ;~ RunWait('PowerShell.exe -Command "& {Add-Computer -WorkGroupName }"') ;~ DllCall("kernel32.dll", "boolean", "Wow64DisableWow64FsRedirection", "boolean", 0) ;~ Turns Off 64 Bit Redirection ;~Else ;~ RunWait('PowerShell.exe -Command "& {Add-Computer -WorkGroupName }"') ;~EndIf EndIf i still don't understand why your code does not work and the one above does Link to comment Share on other sites More sharing options...
Subz Posted April 3, 2017 Share Posted April 3, 2017 As mentioned I never tested, I just coded the PowerShell script you posted above into AutoIt. If the code above works try the following: #RequireAdmin #include <WinAPIFiles.au3> Local $sComputerName = "New Name" Local $sWorkGroup = "WORKGROUPA" Local $sHKLMRoot @OSArch = "x64" ? "HKLM64" : "HKLM" Local $idMsgBox = MsgBox(49, "Computer Rename", "Rename Computer to: " & $sComputerName & @CRLF & "Join WorkGroup: " & $sWorkGroup & @CRLF & "Do you wish to continue?") If $idMsgBox = 6 Then RegWrite($sHKLMRoot & "\SYSTEM\CurrentControlSet\Control\ComputerName\ActiveComputerName", "ComputerName","REG_SZ", $sComputerName) RegWrite($sHKLMRoot & "\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName", "ComputerName", "REG_SZ", $sComputerName) RegWrite($sHKLMRoot & "\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters", "Hostname", "REG_SZ", $sComputerName) RegWrite($sHKLMRoot & "\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters", "NV Hostname", "REG_SZ", $sComputerName) If @OSArch = "x64" Then DllCall("kernel32.dll", "boolean", "Wow64DisableWow64FsRedirection", "boolean", 1) ;~ Turns On 64 Bit Redirection RunWait('PowerShell.exe -Command "& {Add-Computer -WorkGroupName "' & $sWorkGroup & '"}"') DllCall("kernel32.dll", "boolean", "Wow64DisableWow64FsRedirection", "boolean", 0) ;~ Turns Off 64 Bit Redirection Else RunWait('PowerShell.exe -Command "& {Add-Computer -WorkGroupName "' & $sWorkGroup & '"}"') EndIf EndIf I normally would use something like: #RequireAdmin #include <WinAPIFiles.au3> Local $sComputerName = "NewName" Local $sWorkGroup = "WORKGROUPA" Local $idMsgBox = MsgBox(49, "Computer Rename", "Rename Computer to: " & $sComputerName & @CRLF & "Join WorkGroup: " & $sWorkGroup & @CRLF & "Do you wish to continue?") If $idMsgBox = 6 Then If @OSArch = "x64" Then DllCall("kernel32.dll", "boolean", "Wow64DisableWow64FsRedirection", "boolean", 1) ;~ Turns On 64 Bit Redirection RunWait('PowerShell.exe -Command "& {Add-Computer -WorkGroupName "' & $sWorkGroup & '" -NewName "' & $sComputerName & '"}"') DllCall("kernel32.dll", "boolean", "Wow64DisableWow64FsRedirection", "boolean", 0) ;~ Turns Off 64 Bit Redirection Else RunWait('PowerShell.exe -Command "& {Add-Computer -WorkGroupName "' & $sWorkGroup & '" -NewName "' & $sComputerName & '"}"') EndIf EndIf Link to comment Share on other sites More sharing options...
antonioj84 Posted April 3, 2017 Share Posted April 3, 2017 HI Subz None of the code you posted above works !! Link to comment Share on other sites More sharing options...
Subz Posted April 3, 2017 Share Posted April 3, 2017 Are you compiling as x86 or x64? It should be x86, if I get a chance tomorrow I'll test it on one of my Test systems. Link to comment Share on other sites More sharing options...
antonioj84 Posted April 3, 2017 Share Posted April 3, 2017 (edited) #RequireAdmin ;#include <WinAPIFiles.au3> Local $sComputerName = "New Name" Local $sWorkGroup = "WORKGROUPA" Local $sHKLMRoot ="HKLM" Rename($sComputerName) Func Rename($name) RegWrite("HKLM\SYSTEM\CurrentControlSet\Control\ComputerName\ActiveComputerName", "ComputerName","REG_SZ", $name) RegWrite("HKLM\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName", "ComputerName", "REG_SZ", $name) RegWrite("HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters", "Hostname", "REG_SZ", $name) RegWrite("HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters", "NV Hostname", "REG_SZ", $name) RunWait('PowerShell.exe -Command "& {Add-Computer -WorkGroupName "' & $sWorkGroup & '"}"') Return 0 EndFunc This work !! could be the reason I am compiling in x86, no reboot required Edited April 3, 2017 by antonioj84 update Link to comment Share on other sites More sharing options...
antonioj84 Posted April 3, 2017 Share Posted April 3, 2017 Your code error out Link to comment Share on other sites More sharing options...
antonioj84 Posted April 3, 2017 Share Posted April 3, 2017 (edited) #RequireAdmin #include <WinAPIFiles.au3> Global $sComputerName = "Lenovo-PC12" Global $sWorkGroup = "WORKGROUP12" Global $CMD='net config server /srvcomment:"' Rename($sComputerName) Func Rename($name) RegWrite("HKLM\SYSTEM\CurrentControlSet\Control\ComputerName\ActiveComputerName", "ComputerName","REG_SZ", $name) RegWrite("HKLM\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName", "ComputerName", "REG_SZ", $name) RegWrite("HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters", "Hostname", "REG_SZ", $name) RegWrite("HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters", "NV Hostname", "REG_SZ", $name) RunWait(@ComSpec & " /c " & $CMD&$sComputerName ,"", "", @SW_HIDE) ; adding computer description name RunWait('PowerShell.exe -Command "& {Add-Computer -WorkGroupName "' & $sWorkGroup & '"}"') ; adding to workgroup ;RunWait('PowerShell.exe -Command "& {Add-Computer -WorkGroupName "' & $sWorkGroup & '" -Description "' & $sComputerName & '"}"') Return 0 EndFunc here is the final code and work like a charm on Windows10, if you can improve on it, that will be just great, like hiding Powershell window ect.. NO REBOOTING REQUIRED Edited April 3, 2017 by antonioj84 error Link to comment Share on other sites More sharing options...
Subz Posted April 3, 2017 Share Posted April 3, 2017 Did you try adding @SW_HIDE to PowerShell Run Command? Link to comment Share on other sites More sharing options...
antonioj84 Posted April 4, 2017 Share Posted April 4, 2017 RunWait('PowerShell.exe -Command "& {Add-Computer -WorkGroupName "' & $sWorkGroup & '"}"',"",@SW_HIDE) Yes that does it Link to comment Share on other sites More sharing options...
antonioj84 Posted April 4, 2017 Share Posted April 4, 2017 expandcollapse popup#RequireAdmin #include <WinAPIFiles.au3> Global $sComputerName = "Lenovo-PC1" Global $sWorkGroup = "wORKGROUp1" Global $CMD='net config server /srvcomment:"' Global $sHKLMRoot If @OSArch = "x64" Then $sHKLMRoot = "HKLM64" Else $sHKLMRoot = "HKLM" EndIf Rename($sComputerName) MsgBox(0,"done","completed") Func Rename($name) RegWrite($sHKLMRoot&"\SYSTEM\CurrentControlSet\Control\ComputerName\ActiveComputerName", "ComputerName","REG_SZ",StringUpper($name)) RegWrite($sHKLMRoot&"\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName", "ComputerName", "REG_SZ", StringUpper($name)) RegWrite($sHKLMRoot&"\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters", "Hostname", "REG_SZ", StringUpper($name)) RegWrite($sHKLMRoot&"\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters", "NV Hostname", "REG_SZ", StringUpper($name)) RunWait(@ComSpec & " /c " & $CMD& StringUpper($sComputerName) ,"", "", @SW_HIDE) ; adding computer description name If @OSArch = "x64" Then DllCall("kernel32.dll", "boolean", "Wow64DisableWow64FsRedirection", "boolean", 1) ;~ Turns On 64 Bit Redirection RunWait('PowerShell.exe -Command "& {Add-Computer -WorkGroupName "' & StringUpper($sWorkGroup) & '"}"',"",@SW_HIDE) ; adding to workgroup DllCall("kernel32.dll", "boolean", "Wow64DisableWow64FsRedirection", "boolean", 0) ;~ Turns Off 64 Bit Redirection Else RunWait('PowerShell.exe -Command "& {Add-Computer -WorkGroupName "' & StringUpper($sWorkGroup) & '"}"',"",@SW_HIDE) ; adding to workgroup EndIf Return 0 EndFunc final version added subz codes, this code will add the pc to workgroup , pc name, description NO REBOOTING REQUIRED Link to comment Share on other sites More sharing options...
antonioj84 Posted April 6, 2017 Share Posted April 6, 2017 RequireAdmin #include <WinAPIFiles.au3> Global $sHKLMRoot If @OSArch = "x64" Then $sHKLMRoot = "HKLM64" Else $sHKLMRoot = "HKLM" EndIf If @OSArch = "x64" Then DllCall("kernel32.dll", "boolean", "Wow64DisableWow64FsRedirection", "boolean", 1) ;~ Turns On 64 Bit Redirection Regwrite($sHKLMRoot&' \system\currentcontrolset\services\tcpip\parameters /v "SearchList" /d "domain1.com,domain2.com" /f') DllCall("kernel32.dll", "boolean", "Wow64DisableWow64FsRedirection", "boolean", 0) ;~ Turns Off 64 Bit Redirection Else Regwrite($sHKLMRoot&' \system\currentcontrolset\services\tcpip\parameters /v "SearchList" /d "domain1.com,domain2.com" /f') EndIf HEY subz, i am trying to write dns suffixes with the code above wont work, however the dos command below works (please help) reg add HKLM\system\currentcontrolset\services\tcpip\parameters /v "SearchList" /d "domain1.com,domain2.com" /f Link to comment Share on other sites More sharing options...
Subz Posted April 6, 2017 Share Posted April 6, 2017 (edited) You had a space between ' and first backslash "\" What about: #RequireAdmin Global $sHKLMRoot = @OSArch = "x64" ? "HKLM64" : "HKLM" Regwrite($sHKLMRoot & '\System\CurrentControlSet\Services\tcpip\parameters', "SearchList", 'REG_SZ', "domain1.com,domain2.com") Edited April 6, 2017 by Subz Link to comment Share on other sites More sharing options...
antonioj84 Posted April 6, 2017 Share Posted April 6, 2017 #RequireAdmin #include <WinAPIFiles.au3> Global $sHKLMRoot = @OSArch = "x64" ? "HKLM64" : "HKLM" Regwrite($sHKLMRoot & '\System\CurrentControlSet\Services\tcpip\parameters /v "SearchList" /d "domain1.com,domain2.com" /f') no it still not writing i spent 3 hours so far, i code look promising, try the code below at the DOS prompt reg add HKLM\system\currentcontrolset\services\tcpip\parameters /v "SearchList" /d "domain1.com,domain2.com" /f Link to comment Share on other sites More sharing options...
Subz Posted April 6, 2017 Share Posted April 6, 2017 Can you place a MsgBox with @error to see what error it's returning + check if the Registry key is getting created or not? Link to comment Share on other sites More sharing options...
antonioj84 Posted April 6, 2017 Share Posted April 6, 2017 (edited) Edited April 6, 2017 by antonioj84 ok Link to comment Share on other sites More sharing options...
Subz Posted April 6, 2017 Share Posted April 6, 2017 Sorry brain was else where: #RequireAdmin Global $sHKLMRoot = @OSArch = "x64" ? "HKLM64" : "HKLM" Regwrite($sHKLMRoot & '\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters', 'SearchList', 'REG_SZ', 'domain1.com,domain2.com') 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