Jump to content
jshapy8

Trouble with script that joins to the domain

Recommended Posts

jshapy8

I am modifying a script that I found on a support form online a while back. It seems to work pretty well. However, when I input my username and password in the script, when running, the computer is unable to join to the domain because it claims the username or password I entered is bad. I am certain it is correct. Here is the code:

 

#RequireAdmin
$ComputerName = InputBox("Computer Name Required", "Please enter the Computer Name", "")

ShellExecute("sysdm.cpl")

WinWait("System Properties")
WinActivate("System Properties","To use a wizard to join a domain or workgroup")

Send("!C")

WinWait("Computer Name/Domain Changes", "You can change the name and")
WinActivate("Computer Name/Domain Changes", "You can change the name and")
Send("!C")
Send($ComputerName)
Send("!D")
Send("{TAB}")
Send("mydomain.pvt")
Send("{ENTER}")

WinWait("Windows Security", "OK")
WinActivate("Windows Security", "OK")
Send("mydomain\username")
Send("{TAB}")
Send("password")
Send("{TAB}")
Send("{ENTER}")

WinWait("Computer Name/Domain Changes", "Welcome to the mydomain.pvt domain.")
WinActivate("Computer Name/Domain Changes", "Welcome to the mydomain.pvt domain.")
Send("{ENTER}")

Sleep(15000)
if WinExists("Computer Name/Domain Changes", "OK") Then
    Send("{ENTER}")
EndIf

WinWait("System Properties", "To use a wizard")
WinActivate("System Properties","To use a wizard")
Send("{ENTER}")

WinWait("Microsoft Windows", "&Restart Now")
WinActivate("Microsoft Windows", "&Restart Now")
Send("!R")
 

Any ideas? The username and password is certainly correct. Is there a Windows security feature that is able to detect that you are running an automation script?

Edited by jshapy8

Share this post


Link to post
Share on other sites
JLogan3o13

Hi, jshapy8, welcome to the forum. Take a look at the A.D. functions in the help file, especially _AD_JoinDomain. It will make your life much easier ;)


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
jshapy8

Hi, jshapy8, welcome to the forum. Take a look at the A.D. functions in the help file, especially _AD_JoinDomain. It will make your life much easier ;)

​I actually have looked at that one in the past. I would just like to simply automate the task that I would usually complete to join to the domain. Also I am frankly just generally interested in why my credentials don't work using this script. It should work, shouldn't it?

Share this post


Link to post
Share on other sites
JLogan3o13

"Should" is a relative term. I have a number of scripts for domain work, and run them all in the context of my domain admin account, and yes, they all work. But you are doing a lot of send in your script, and have no real error checking (hard to do when you're just sending keystrokes), so beyond saying "Yes, it should work", it is difficult to point you to a potential cause for failure.


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
jshapy8

​I figured out the issue. The problem was at there was an exclamation point in my password. I had to write a separate send command for the exclamation point rather than just including it in one string with the rest of the password. 

Share this post


Link to post
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

×