Jump to content

can't see the forest for the trees


Remo1075
 Share

Recommended Posts

Hi folks

Having problems on some syntax, the 1st script works fine. But I don't want to leave the username and password in the script.

$path="netdom join "& @ComputerName & " /domain:test.local\server.test.local /userd:test\admin /passwordd:password"

RunWait(@ComSpec & ' /c ' & $path)

want it more like

input box used to get username and password; no problem with this part

$passwd="password"

$username"username"

$path="netdom join "& @ComputerName & " /domain:test.local\server.test.local"

RunWait(@ComSpec & ' /c ' & $path, & "/userd:test\"& $username, & "/passwordd:"& $passwd")

just getting a bit stuck with how to mesh this together,

Link to comment
Share on other sites

Syntax is

RunWait(@ComSpec & ' /c' & "command")

So only first and last sign from command are: "

Your $path and function call should be:

$path='"netdom join ' & @ComputerName & ' /domain:test.local\server.test.local'
RunWait(@ComSpec & ' /c ' & $path, & ' /userd:test\' & $username, & ' /passwordd:' & $passwd & '"')

btw:

Wrong forum here, should post in 'General Help and Support'

Edited by BugFix

Best Regards BugFix  

Link to comment
Share on other sites

Thanks guys for the help; I chose a slightly differnent way. But here is my simple script to join a domain.

I have seen a few others out there but are far too slow for what I want. I'd like one for each site. We have a desktop ou and laptop ou for every site so it makes sense having it a bit faster than other scripts. Tell me what you all think. BTW sorry for posting in the wrong area, my bad.

#cs
Join PC to the Domain and add to correct OU
Written By Matt Addy
;#ce

;-------------------------------------------------------------------------------
;connect to server & ping 
TCPStartup()
while TCPNameToIP("server") = ""
    Sleep (3000)
WEnd
TCPShutdown ( )

DriveMapAdd("Z:","\\server\share$",8)

;copy netdom to C:\Windows\System32 
FileCopy("Z:\Share\netdom.exe", "C:\WINDOWS\system32")
FileCopy("Z:\Share\compname.exe", "C:\WINDOWS\system32")
FileCopy("Z:\Share\dsadd.exe", "C:\WINDOWS\system32")

;Splash only for City/Site use
SplashTextOn("", "Only to be used for City/Site PC's", 550, 60, -1, -1, 3, "", 24)
Sleep(2000)
SplashOff()

;Rename Computer
$bLoop = 1
While $bLoop = 1
$computername = InputBox("Computer", "Enter Computer Name...")
If @error = 1 Then
Exit ;MsgBox(4096, "Error", "You pressed 'Cancel' - try again!")
Else
If $computername = "" Then
MsgBox(4096, "Error", "You must enter a name")
Else
$bLoop = 0 
EndIf
EndIf
WEnd
RunWait(@ComSpec & " /c " & "compname.exe /c " & $computername, "", @SW_HIDE)

;Ask for username
Dim $username, $passwd
$bLoop = 1
While $bLoop = 1
$username = InputBox("Username", "Please enter your username and click OK", "", "")
If @error = 1 Then
exit ;MsgBox(4096, "Error", "You pressed 'Cancel' - try again!")
Else
If $username = "" Then
MsgBox(4096, "Error", "You must enter your username")
Else
$bLoop = 0 
EndIf
EndIf
WEnd

;Ask for password
$bLoop = 1
While $bLoop = 1
$passwd = InputBox("Password", "Please enter your password and click OK", "", "*")
If @error = 1 Then
exit ;MsgBox(4096, "Error", "You pressed 'Cancel' - try again!")
Else
If $passwd = "" Then
MsgBox(4096, "Error", "You must enter your password")
Else
$bLoop = 0 
EndIf
EndIf
WEnd

;change hostname to same as new pc name, put it here so it gives compname.exe a bit more time to change pc name.
RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\Tcpip\Parameters", "Hostname", "REG_SZ", $computername)

;Join Computer to Domain
$type = MsgBox(4, "Type", "Is This a Laptop ?")
If $type = 6 Then ;laptop
    RunWait(@comspec & " /c dsadd computer -s server.test.local CN="& $computername & ",OU=laptop,OU=home,DC=remo,DC=local -u " & $username & " -p " & $passwd, "", @SW_HIDE)
    $path='"netdom join '& @ComputerName &' /domain:test.local\server.test.local /userd:test\'& $username &' /passwordd:'& $passwd &'"'
    RunWait(@ComSpec & ' /c ' & $path, "", @SW_HIDE)


Else
If $type = 7 Then ;desktop
    RunWait(@comspec & " /c dsadd computer -s server.test.local CN="& $computername & ",OU=desktop,OU=home,DC=test,DC=local -u " & $username & " -p " & $passwd, "", @SW_HIDE)
    $path='"netdom join '& @ComputerName &' /domain:test.local\server.test.local /userd:test\'& $username &' /passwordd:'& $passwd &'"'
    RunWait(@ComSpec & ' /c ' & $path, "", @SW_HIDE)
Else 
MsgBox(16,"Error", "Couldn't Join PC to Domain..")
Exit
EndIf
EndIf

SplashTextOn("", & $computername " has joined the Domain", 550, 60, -1, -1, 3, "", 24)
Sleep(2000)
SplashOff()
Exit

Just need to work on the end spalsh ;-)

Edited by Remo1075
Link to comment
Share on other sites

Thanks guys for the help; I chose a slightly differnent way. But here is my simple script to join a domain.

I have seen a few others out there but are far too slow for what I want. I'd like one for each site. We have a desktop ou and laptop ou for every site so it makes sense having it a bit faster than other scripts. Tell me what you all think. BTW sorry for posting in the wrong area, my bad.

#cs
Join PC to the Domain and add to correct OU
Written By Matt Addy
;#ce

;-------------------------------------------------------------------------------
;connect to server & ping 
TCPStartup()
while TCPNameToIP("server") = ""
    Sleep (3000)
WEnd
TCPShutdown ( )

DriveMapAdd("Z:","\\server\share$",8)

;copy netdom to C:\Windows\System32 
FileCopy("Z:\Share\netdom.exe", "C:\WINDOWS\system32")
FileCopy("Z:\Share\compname.exe", "C:\WINDOWS\system32")
FileCopy("Z:\Share\dsadd.exe", "C:\WINDOWS\system32")

;Splash only for City/Site use
SplashTextOn("", "Only to be used for City/Site PC's", 550, 60, -1, -1, 3, "", 24)
Sleep(2000)
SplashOff()

;Rename Computer
$bLoop = 1
While $bLoop = 1
$computername = InputBox("Computer", "Enter Computer Name...")
If @error = 1 Then
Exit ;MsgBox(4096, "Error", "You pressed 'Cancel' - try again!")
Else
If $computername = "" Then
MsgBox(4096, "Error", "You must enter a name")
Else
$bLoop = 0 
EndIf
EndIf
WEnd
RunWait(@ComSpec & " /c " & "compname.exe /c " & $computername, "", @SW_HIDE)

;Ask for username
Dim $username, $passwd
$bLoop = 1
While $bLoop = 1
$username = InputBox("Username", "Please enter your username and click OK", "", "")
If @error = 1 Then
exit ;MsgBox(4096, "Error", "You pressed 'Cancel' - try again!")
Else
If $username = "" Then
MsgBox(4096, "Error", "You must enter your username")
Else
$bLoop = 0 
EndIf
EndIf
WEnd

;Ask for password
$bLoop = 1
While $bLoop = 1
$passwd = InputBox("Password", "Please enter your password and click OK", "", "*")
If @error = 1 Then
exit ;MsgBox(4096, "Error", "You pressed 'Cancel' - try again!")
Else
If $passwd = "" Then
MsgBox(4096, "Error", "You must enter your password")
Else
$bLoop = 0 
EndIf
EndIf
WEnd

;change hostname to same as new pc name, put it here so it gives compname.exe a bit more time to change pc name.
RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\Tcpip\Parameters", "Hostname", "REG_SZ", $computername)

;Join Computer to Domain
$type = MsgBox(4, "Type", "Is This a Laptop ?")
If $type = 6 Then ;laptop
    RunWait(@comspec & " /c dsadd computer -s server.test.local CN="& $computername & ",OU=laptop,OU=home,DC=remo,DC=local -u " & $username & " -p " & $passwd, "", @SW_HIDE)
    $path='"netdom join '& @ComputerName &' /domain:test.local\server.test.local /userd:test\'& $username &' /passwordd:'& $passwd &'"'
    RunWait(@ComSpec & ' /c ' & $path, "", @SW_HIDE)


Else
If $type = 7 Then ;desktop
    RunWait(@comspec & " /c dsadd computer -s server.test.local CN="& $computername & ",OU=desktop,OU=home,DC=test,DC=local -u " & $username & " -p " & $passwd, "", @SW_HIDE)
    $path='"netdom join '& @ComputerName &' /domain:test.local\server.test.local /userd:test\'& $username &' /passwordd:'& $passwd &'"'
    RunWait(@ComSpec & ' /c ' & $path, "", @SW_HIDE)
Else 
MsgBox(16,"Error", "Couldn't Join PC to Domain..")
Exit
EndIf
EndIf

SplashTextOn("", & $computername " has joined the Domain", 550, 60, -1, -1, 3, "", 24)
Sleep(2000)
SplashOff()
Exit

Just need to work on the end spalsh ;-)

I wrote the below code to add some more control on joining the domain, should be easy add on.

$strComputer ="Localhost"
$4 = "test.com"
$1 = ObjGet("winmgmts:{impersonationLevel=Impersonate}!\\" & $strComputer & "\root\cimv2")
If Not IsObj($1) Then Exit

;Get Computername
$2 = $1.ExecQuery ("SELECT * FROM Win32_Computersystem")
For $3 in $2
$result = ($3.Domain)
Next    
if $result = $4 Then
    msgbox(0, "", "Welcome to the domain")
Else
MsgBox(16,"Error", "Something Went Horribly Wrong, Try Again...",3)     
EndIf
Link to comment
Share on other sites

  • 2 weeks later...

So I was having trouble with joining the domain and had to add some more regwrite keys. The script should now work

perfectly. You can verify if the pc is a member of the domain after a reboot by using. Netdom verify name of pc from the client.

#cs
Join PC to the Domain and add to correct OU Written by Matt Addy
;#ce

;-------------------------------------------------------------------------------
;connect to server ping 
TCPStartup()
while TCPNameToIP("server where netdom is") = ""
    Sleep (3000)
WEnd
TCPShutdown ( )

DriveMapAdd("B:","\\server\share$",8)

;copy netdom to C:\Windows\System32 
FileCopy("B:\folder\netdom.exe", "C:\WINDOWS\system32")
FileCopy("B:\folder\compname.exe", "C:\WINDOWS\system32")
FileCopy("B:\folder\dsadd.exe", "C:\WINDOWS\system32")

#ce

;Splash only for winterthur use
SplashTextOn("", "Only to be used for site name PC's", 550, 60, -1, -1, 3, "", 24)
Sleep(2300)
SplashOff()

;Rename Computer
$bLoop = 1
While $bLoop = 1
$computername = InputBox("Computer", "Enter Computer Name...")
If @error = 1 Then
Exit ;MsgBox(4096, "Error", "You pressed 'Cancel' - try again!")
Else
If $computername = "" Then
MsgBox(4096, "Error", "You must enter a name")
Else
$bLoop = 0 
EndIf
EndIf
WEnd
RunWait(@ComSpec & " /c " & "compname.exe /c " & $computername, "", @SW_HIDE)

;Ask for username
Dim $username, $passwd
$bLoop = 1
While $bLoop = 1
$username = InputBox("Username", "Please enter your username and click OK", "", "")
If @error = 1 Then
exit ;MsgBox(4096, "Error", "You pressed 'Cancel' - try again!")
Else
If $username = "" Then
MsgBox(4096, "Error", "You must enter your username")
Else
$bLoop = 0 
EndIf
EndIf
WEnd

;Ask for password
$bLoop = 1
While $bLoop = 1
$passwd = InputBox("Password", "Please enter your password and click OK", "", "*")
If @error = 1 Then
exit ;MsgBox(4096, "Error", "You pressed 'Cancel' - try again!")
Else
If $passwd = "" Then
MsgBox(4096, "Error", "You must enter your password")
Else
$bLoop = 0 
EndIf
EndIf
WEnd

;change hostname to same as new pc name, put it here so it gives compname.exe a bit more time to chnage pc name.
RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\Tcpip\Parameters", "Hostname", "REG_SZ", $computername)

RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\ComputerName\ActiveComputerName", "ComputerName", "REG_SZ", $computername)
RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName", "ComputerName", "REG_SZ", $computername)
RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters", "Hostname", "REG_SZ", $computername)
RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters", "NV Hostname", "REG_SZ", $computername)

 

;Join Computer to Domain
$type = MsgBox(4, "Type", "Is This a Laptop ?")
If $type = 6 Then ;laptop
    RunWait(@comspec & " /c dsadd computer -s domain.com CN="& $computername & ",OU=laptop,DC=domain,DC=com -u " & $username & " -p " & $passwd, "", @SW_HIDE)
    $path='"netdom join '& @ComputerName &' /domain:domain.com\server.domain.com /userd:domain\'& $username &' /passwordd:'& $passwd &'"'
    RunWait(@ComSpec & ' /c ' & $path, "", @SW_HIDE)


Else
If $type = 7 Then ;desktop
    RunWait(@comspec & " /c dsadd computer -s server.domain.com CN="& $computername & ",OU=desktop,DC=domain,DC=com -u " & $username & " -p " & $passwd, "", @SW_HIDE)
    $path='"netdom join '& @ComputerName &' /domain:domain.com\server.domain.com /userd:domain\'& $username &' /passwordd:'& $passwd &'"'
    RunWait(@ComSpec & ' /c ' & $path, "", @SW_HIDE)
Else 
MsgBox(16,"Error, Maybe Wrong Password", "Couldn't Join PC to Domain..")
Exit
EndIf
EndIf

$strComputer ="Localhost"
$4 = "doamin.com"
$1 = ObjGet("winmgmts:{impersonationLevel=Impersonate}!\\" & $strComputer & "\root\cimv2")
If Not IsObj($1) Then Exit

;Get Computername
$2 = $1.ExecQuery ("SELECT * FROM Win32_Computersystem")
For $3 in $2
$result = ($3.Domain)
Next    
if $result = $4 Then
    SplashTextOn("", & $computername " has joined the Domain", 620, 60, -1, -1, 1, "", 24)
Sleep(3000)
SplashOff()
Run(@ComSpec & " /c " & 'lusrmgr.msc ', "", @SW_HIDE)
WinWaitActive("Local Users and Groups", "", 10)
Send("{Down}")
Sleep(100)
Send("{Down}")
Sleep(500)
Send("{Tab}")
Sleep(500)
Send("{Enter}")
WinWaitActive("Administrators Properties", "", 10)
Controlclick("Administrators Properties", "", "Button1", "")
WinWaitActive("Select Users, Computers, or Groups", "", 5)
ControlClick("Select Users, Computers, or Groups", "", "Button4", "")
Else
MsgBox(16,"Error", "Something Went Horribly Wrong, Try Again...",3)     
EndIf   

Exit
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...