Jump to content

Rename pc and Join to domain


HaeMHuK
 Share

Recommended Posts

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 by Subz
Link to comment
Share on other sites

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

#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

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

#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

ThisworkCapture.JPG

Edited by antonioj84
update
Link to comment
Share on other sites

#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

goodCapture.JPG

Edited by antonioj84
error
Link to comment
Share on other sites

#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

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

#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
 

nodnsCapture.JPG

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...