Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

domain join script

Status
Not open for further replies.

Briandr

MIS
Jul 11, 2003
177
US
Hi All,

Can someone see anything wrong with this script. It executes, but the computer never joins the domain.

Const JOIN_DOMAIN = 1
Const ACCT_CREATE = 2
Const ACCT_DELETE = 4
Const WIN9X_UPGRADE = 16
Const DOMAIN_JOIN_IF_JOINED = 32
Const JOIN_UNSECURE = 64
Const MACHINE_PASSWORD_PASSED = 128
Const DEFERRED_SPN_SET = 256
Const INSTALL_INVOCATION = 262144

strDomain = "ANYORG.ORG"
strPassword = "fixme"
strUser = "ANYORG\joindomain"

Set objNetwork = CreateObject("WScript.Network")
strComputer = objNetwork.ComputerName

Set objComputer = GetObject("winmgmts:{impersonationLevel=Impersonate}!\\" & _
strComputer & "\root\cimv2:Win32_ComputerSystem.Name='" & _
strComputer & "'")

ReturnValue = objComputer.JoinDomainOrWorkGroup(strDomain, _
strPassword, strDomain & "\" & strUser, NULL, _
JOIN_DOMAIN + ACCT_CREATE)
 
Never thought of controlling Windows networking from Excel VBA before. Are you sure you aren't running into system-based security restrictions there? Could be it's just blocked from changing the settings via such a script..

Interesting concept, nonetheless... one that I could have used in some scenarios, I think.
 
Why this ?
strUser = "ANYORG\joindomain"
As you use this:
strPassword, [!]strDomain & "\" &[/!] strUser, NULL, _

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
kjv1611:

I was not told this was an Excel VBA.


PHV:

Had to make up some information that would not identify my employer. It could have been something like 'ABC'. Was not feeling too creative when I pasted.
 
Oh, whoops. [blush] I just assumed the application. So what application is it in? This is the VBA forum, so should be a safe guess that it's supposedly running in VBA for some Office application.

If not, then what application is it running in, how is it running?


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top