Hi,
I have created a script for joining a PC to domain. It works fine when
I run it on a single machine. But when I run it remotely on networked
PC it is not working.

Any Idea....?


Thanks
Jaydeep

Re: Domain Joining. by Jim

Jim
Tue Jun 13 07:52:14 CDT 2006

pretty hard to say without seeing the code... wouldnt you agree?



"jay_kbvt" <jaydeep.kubavat@gmail.com> wrote in message
news:1150179332.717284.89570@y43g2000cwc.googlegroups.com...
> Hi,
> I have created a script for joining a PC to domain. It works fine when
> I run it on a single machine. But when I run it remotely on networked
> PC it is not working.
>
> Any Idea....?
>
>
> Thanks
> Jaydeep
>



Re: Domain Joining. by jay_kbvt

jay_kbvt
Wed Jun 14 05:12:03 CDT 2006

It works fine when strComputer = "."
But when stComputer = (some IP Address) it doesn't work.

Below is the code:

On Error Resume Next

Const JOIN_DOMAIN = 1
Const ACCT_CREATE = 2

strComputer = "."
strDNSSrv = "190.2.220.20;190.3.220.20"
'InputBox ("Enter DNS Servers. Use ';' as Seperater.")

arrDNSSrv = Split (strDNSSrv, ";")

Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colNicCfg = objWMIService.ExecQuery _
("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled =
True")

For Each objniccfg In colNicCfg
WScript.Echo objniccfg.DNSServerSearchOrder
objniccfg.SetDNSServerSearchOrder(arrDNSSrv)
WScript.Echo "New DNS Server Search Order:" &
objniccfg.DNSServerSearchOrder
Next

strDomainName = InputBox("Domain Name.")
strPassword = InputBox("Password.")
strUser = InputBox("User Name.")

Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colCompSystems = objWMIService.ExecQuery _
("SELECT * FROM Win32_ComputerSystem")

For Each objCompSystem In colCompSystems
WScript.Echo VbCrLf & "Computer Name: " & LCase(objCompSystem.Name)
WScript.Echo " Current Domain: " & LCase(objCompSystem.Domain)
intJoinDomain = objCompSystem.JoinDomainOrWorkgroup(strDomainName,
strPassword, strUser, , JOIN_DOMAIN + ACCT_CREATE)
If intJoinDomain = 0 Then
WScript.Echo " Joined computer to " & strDomainName & " domain."
ElseIf intJoinDomain = 1 Then
WScript.Echo " Joined computer to " & strDomainName & " domain."
& _
VbCrLf & " Must reboot."
Else
WScript.Echo " Unable to join computer to " & strDomainName & _
" domain."
WScript.Echo "Return value of JoinDomainOrWorkgroup method: " &
intJoinDomain
End If
Next

Thanks & Regards
Jaydeep.