Jump to content

ShellExecute Netdom Renamecomputer


UniPer
 Share

Recommended Posts

Why doesn't this work:

$netdom = '"C:\temp\netdom"'

Dim $reg = "RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Organization\Setup", "MachineSerial")
Dim $serial = "NL-"& $reg

ShellExecute ( $netdom, 'renamecomputer . /UserD:admin /PasswordD:admin /newname:"'& $serial &'"' )
Sleep (2000)
send ("{y}")
Sleep (1000)

It reads the registry, it creates the variable $serial perfectly, but it doesn't run the 'netdom' command as it should.

If someone can help me out with this that would be just great :)

Edited by UniPer
Link to comment
Share on other sites

Why doesn't this work:

$netdom = '"C:\temp\netdom"'

Dim $reg = "RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Organization\Setup", "MachineSerial")
Dim $serial = "NL-"& $reg

ShellExecute ( $netdom, 'renamecomputer . /UserD:admin /PasswordD:admin /newname:"'& $serial &'"' )
Sleep (2000)
send ("{y}")
Sleep (1000)

It reads the registry, it creates the variable $serial perfectly, but it doesn't run the 'netdom' command as it should.

If someone can help me out with this that would be just great :)

eh, netdom.exe? and why the double quotes on netdom variable..

$netdom = "c:\temp\netdom.exe"oÝ÷ Ù©Ýj[(jëh×6RunWait($netdom & ' renamecomputer . /UserD:admin /PasswordD:admin /newname:'& $serial'')
Edited by skysel
Link to comment
Share on other sites

Thanks for the suggestions but after I changed this I get:

C:\temp\parts\rename.au3(26,96) : ERROR: syntax error
RunWait ($netdom & ' renamecomputer . /UserD:admin /PasswordD:admin /newname:'& $serial''
oops my mistake..

RunWait($netdom & ' renamecomputer . /UserD:admin /PasswordD:admin /newname:'& $serial)

too much quotes at the end :) Besides, recheck the netdom.exe syntax.. Is that "." needed ?

Link to comment
Share on other sites

too much quotes at the end Besides, recheck the netdom.exe syntax.. Is that "." needed ?

Yes, the quotes are needed :)

oops my mistake..

CODE: AutoItRunWait($netdom & ' renamecomputer . /UserD:admin /PasswordD:admin /newname:'& $serial)

Ok great :) I don't get any syntax errors anymore but the system name is not changed after running this script.

It seems that the 'netdom' command has a problem running with the /newname:&'$serial).

Normally netdom.exe will return an error message to tell me what's going wrong but...running this script I can't see any errors msg from netdom...

Link to comment
Share on other sites

Yes, the quotes are needed :)

Ok great o:) I don't get any syntax errors anymore but the system name is not changed after running this script.

It seems that the 'netdom' command has a problem running with the /newname:&'$serial).

Normally netdom.exe will return an error message to tell me what's going wrong but...running this script I can't see any errors msg from netdom...

Note that your quotation mark in your reply is /newname:&'$serial), but in my example the quotation mark is in the right place. Maybe thats the problem? :)

RunWait($netdom & ' renamecomputer . /UserD:admin /PasswordD:admin /newname:'& $serial)
Link to comment
Share on other sites

Sorry my mistake in my script I used it correct... so that can't be the problem...

I believe syntax you're using is wrong..

Syntax for netdom is:

NetDom renamecomputer Computer /newname:NewComputerName /userd:[Domain\]UserName [/passwordd:[Password | *]] /usero:[Domain\]UserName [/passwordo:[Password | *]] [/reboot[:Delay]] [{/help | /?}]
Link to comment
Share on other sites

I think not because when I use the following command manual by typing it into a 'cmd' screen it works:

C:\temp\netdom renamecomputer . /UserD:admin /PasswordD:admin /newname:Test12345

So...netdom seems to have a problem with the '& $serial) part.

Link to comment
Share on other sites

Try this I will leave the cmd window open when it finish running netdom and you can see the error.

CODE: AutoItRunWait(@ComsPec & ' /k ' & $netdom & ' renamecomputer . /UserD:admin /PasswordD:admin /newname:'& $serial)

Hehehe :) Allright...I hoped it was something serious but I recieved the message "Name allready exists on the domain" :)

So...deleted the account and you know what....IT'S WORKING o:)

Now I'm restoring the PC to basic config to test the whole script at once!

I'll let you all know!

Edited by UniPer
Link to comment
Share on other sites

So that you all know: It works perfect! :)

The only problem is, what I really want is to rename the computername before joining it to the domain,

only as far as I can see, 'netdom.exe' only supports pc's that are joined to a domain.... o:)

Anybody suggestions on how to fix this? :)

Link to comment
Share on other sites

Hi !

if it can help you :

$message = "Sélectionnez le fichier contenant les noms d'ordinateurs."

$var = FileOpenDialog($message, @WindowsDir & "\", "Fichiers texte (*.txt)", 1 + 2 )

If @error Then
    MsgBox(64,"","Vous n'avez sélectionné aucun fichier.")
    Exit
Else
    $var = StringReplace($var, "|", @CRLF)

    $Fichier = FileOpen($var, 0)

    ; Check if file opened for reading OK
    If $Fichier = -1 Then
        MsgBox(16, "Erreur", "Impossible d'ouvrir le fichier.")
        Exit
    EndIf

    ; Read in lines of text until the EOF is reached
    While 1
        $Ligne = FileReadLine($Fichier)
        If @error = -1 Then ExitLoop
        RunWait(@ComSpec & ' /c ' & 'netdom move ' & $Ligne & ' /Domain:freyssinet /Userd:freyssinet\adminppc /Passwordd:ladsp71 /reboot:10', "", @SW_HIDE)
        If @error Then
            FileWriteLine(@WorkingDir & "\Resultats_Migration_Domaine.xls",$Ligne)
        EndIf
    Wend
    FileClose($Fichier)
EndIf

Qui ose gagneWho Dares Win[left]CyberExploit[/left]

Link to comment
Share on other sites

Got it working now. :)

For all who are intrested in how I managed it all I attachted the script. Below I'll explain which files I used and where I used them for:

1. newsid.exe --> To change the SystemID

2. Forum Script --> To rename the PC

3. NETDOM.EXE --> To join the PC to the Domain

4. restore_reg.reg --> To disable the autlogon by resetting so keys and value's

5. stage1.chk / stage2.chk / stage3.chk --> After every part of the script 1 file is copied to the windows dir so the script knows what to do next time it runs.

#include <GUIConstants.au3>

;This script will silently join the PC to the domain and rename it conform the Company Policy.
;Written with: SciTE4AutoIt3 Version 1.76
;Compiled with: AutoIt v3.2.12.1
;This script will run just once
;Created by UniPer
;Variables must be declared before using them

AutoItSetOption("TrayMenuMode",1)

;The name of the application (used as title for message boxes)
Global $appName = "Domain Tool V1.1"
Global $logonFlag = 0 ; 0 - Interactive logon with no profile. 1 - Interactive logon with profile. 2 - Network Global $extraParameters = " /silent" ; " /silent" ""
Global $runAsWaitFlag = @SW_SHOW ; @SW_HIDE @SW_SHOW

$netdom = "C:\temp\netdom.exe"

    If Not FileExists ("C:\windows\stage1.chk") Then
    ;The registry will be overwritten with a fixed username and password and AutoLogon will be enabled
    RegDelete ( "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon", "DefaultDomainName")
    RegDelete ( "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon", "DefaultUserName")
    RegDelete ( "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon", "DefaultPassword")
    RegDelete ( "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon", "AutoAdminLogon")
    RegDelete ( "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon", "ForceAutoLogon")

    RegWrite ( "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon", "DefaultDomainName", "REG_SZ", "")
    RegWrite ( "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon", "DefaultUsername" , "REG_SZ", "*******")
    RegWrite ( "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon", "DefaultPassword" , "REG_SZ", "*******")
    RegWrite ( "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon", "AutoAdminLogon" , "REG_SZ", "1")
    RegWrite ( "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon", "ForceAutoLogon" , "REG_SZ", "1")
    TrayTip($appName & " - Autologon is Enabled", "AutoLogon Enabled.. ", 1)
    TraySetToolTip($appName & " - Autologon is Enabled")
    Sleep ( 3000 )

    ;Newsid.exe will run silently and will provide a new ID for the system
    ShellExecute ( "C:\temp\newsid", "/a" )
    Sleep ( 3000 )
    Send ("{SPACE}")
    TrayTip($appName & " - Your SystemID renewed ", "Your SystemID has been renewed", 1)
    TraySetToolTip($appName & " - Your SystemID renewed " )
    
    ;Stage1.chk will be copied to the Windows directory to be sure the script came this far
    FileCopy ( "C:\temp\stage1.chk", "C:\windows\")
    
    Sleep ( 3000 )
    TrayTip($appName & " - System reboot..", "System will reboot in a few minutes..", 1)
    TraySetToolTip($appName & " - System reboot.." )
    Sleep ( 10000 )
    Shutdown (2)
    
Else
    If Not FileExists ("C:\windows\stage2.chk") then
        ;Script will read the Machine Serialnumber from the registry to convert it into variable $reg
        Dim $reg = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Organization\Setup", "MachineSerial")

        ;$reg will be changed with so that the new serial is: NL-XXXXXXX after that this will be converted to variable $serial 
        Dim $serial="NL-"& $reg
        TrayTip($appName & " - Systemserial is:", "The Machines Serial is "& $serial, 1 )
        TraySetToolTip($appName & " - Systemserial is:")
        
        #include <GUIConstants.au3>

        GUICreate("Rename", 255, 85, 255, 255)
        GUICtrlCreateLabel("Please type the new computername", 5, 5)
        GUICtrlSetState(-1, $GUI_DROPACCEPTED)
        $inv = GUICtrlCreateInput($serial, 75, 25, 100, 20)
        $btn = GUICtrlCreateButton("Rename", 95, 55, 60, 20)
        GUISetState(@SW_SHOW)

        While 1
            $msg = GUIGetMsg()
            Select
                Case $msg = $GUI_EVENT_CLOSE
                    ExitLoop
                Case $msg = $btn
                        _Rename()
                    ExitLoop
            EndSelect
        WEnd
        
        Send ("{}")
        Send ("{SPACE}")

        ;Stage2.chk will be copied to the Windows directory to be sure the script came this far
        FileCopy ( "C:\temp\stage2.chk", "C:\windows\")
        
        send ("{ENTER}")
            
    Shutdown (2)
    
Else
    If Not FileExists ("C:\windows\stage3.chk") then
        ;System will be joined to the Domain
        RunWait (@Comspec & ' /k ' & $netdom & ' join . /Domain:DOMAIN.COM /UserD:******* /PasswordD:******* ')
        Sleep (2000)
        send ("{y}")
        Sleep (2000)
        Send ("{exit}")
        TrayTip($appName & " - System joined DOMAIN", "System joined the DOMAIN.COM Domain", 1)
        TraySetToolTip($appName & " - System joined DOMAIN")
        Sleep ( 3000 )
        TrayTip($appName & " - System reboot..", "System will reboot in a few seconds..", 1)
        TraySetToolTip($appName & " - System reboot..")
    
        ;Stage2.chk will be copied to the Windows directory to be sure the script came this far
        FileCopy ( "C:\temp\stage2.chk", "C:\windows\")
        Sleep (10000)

        ;The Registry will be restored to his old original state and AutoLogon will be disabled
        ShellExecute ( "C:\windows\regedit", "-s C:\temp\restore_reg.reg" )
        TrayTip($appName & " - Autologon is Disabled", "Autologon disabled again", 1)
        TraySetToolTip($appName & " - Autologon is Disabled")
    
        ;Stage3.chk will be copied to the Windows directory to be sure the script came this far
        FileCopy ( "C:\temp\stage3.chk", "C:\windows\")
    
        Sleep ( 3000 )
        TrayTip($appName & " - System reboot..", "System will reboot in a few seconds..", 1)
        TraySetToolTip($appName & " - System reboot..")
        Shutdown ( 2 )
    Else
        MsgBox (4096, "Finished", "System is Configured")
        Shutdown (2)
    EndIf
EndIf
EndIf

    
Func _Rename()

    Run(@ComSpec & " /c sysdm.cpl", "", @SW_HIDE)
    WinWaitActive("System Properties")
    Send("{RIGHT}")
    Send("{TAB}")
    Send("{TAB}")
    Send("{TAB}")
    Send("{ENTER}")
    $x = GUICtrlRead($inv)
    Send($x)
EndFunc   ;==>_Rename

join_domain_p.au3

Edited by UniPer
Link to comment
Share on other sites

Ok...still one problem :)

When I join this PC to the domain with Windows it's automaticly moved to the right container:

\Company\Europe\Country\Workstations

When I use the script to join the PC to the domain it's being added to:

\Computers

The problem is that none of the machines in the \Computers folder gets the company policy o:)

I tried to use the netdom command as follows:

netdom join . /domain:domain.com /ou:"Company\Europe\Country\Workstations" /UserD:admin /PasswordD:password

The strange thing is that when I try that it's giving me the message: Username or Password incorrect or insuffient privelleges.

If I change the string to:

netdom join . /domain:domain.com /UserD:admin /PasswordD:password /OU:"OU=corporate\europe\computers,DC=domain,DC=com"

I get the message that the account allready exicists, but I perform a full domain search for the account it doesn't excist.

Whaaa...I'm going crazy :)

Anyone know what to do?

Edited by UniPer
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...