RunningGag
asked on
VBScript: WMI error joining the domain
I have built a WIndows XP image that we are deploying in our office. Part of the image uses the JoinDomainOrWorkGroup object to add the machine to the domain but the script periodically fails on the line:
Set objComputer = GetObject("winmgmts:{imper sonationLe vel=Impers onate}!\\" & _
strComputer & "\root\cimv2:Win32_Compute rSystem.Na me='" & _
strComputer & "'")
It seems if I reboot the machine a couple of times it will complete the script.
Details:
I am using the code that MS recommends for this task.
http://msdn.microsoft.com/en-us/library/aa392154(VS.85).aspx
The error it throws is:
C:\...\File.vbs (line,3) (null): 0x80041002
When I output the Err.Number to the screen, the error is: 2147217406
I have tried removing the machine from the domain 15 minutes or more before imaging the machine and running the script. No change.
I have tried adding a reboot on the first boot after Sysprep. No Change.
Prior to running this portion of the script, the local computer name and description are changed.
In some instances, I have run the script, had it fail, then run it again a few minutes later and had it complete.
I have also tried setting up a loop in which in the case of errors, validates whether or not the computer has completed joining the domain, and if not, loops back to the start of the Sub.
I'm going to start working on a workaround, but this is my preferred method. I would rather not use Netdom because I don't want to store account credentials in the script.
Ideas? Can someone at least tell me what is happening at that line?
Set objComputer = GetObject("winmgmts:{imper
strComputer & "\root\cimv2:Win32_Compute
strComputer & "'")
It seems if I reboot the machine a couple of times it will complete the script.
Details:
I am using the code that MS recommends for this task.
http://msdn.microsoft.com/en-us/library/aa392154(VS.85).aspx
The error it throws is:
C:\...\File.vbs (line,3) (null): 0x80041002
When I output the Err.Number to the screen, the error is: 2147217406
I have tried removing the machine from the domain 15 minutes or more before imaging the machine and running the script. No change.
I have tried adding a reboot on the first boot after Sysprep. No Change.
Prior to running this portion of the script, the local computer name and description are changed.
In some instances, I have run the script, had it fail, then run it again a few minutes later and had it complete.
I have also tried setting up a loop in which in the case of errors, validates whether or not the computer has completed joining the domain, and if not, loops back to the start of the Sub.
I'm going to start working on a workaround, but this is my preferred method. I would rather not use Netdom because I don't want to store account credentials in the script.
Ideas? Can someone at least tell me what is happening at that line?
Sub DomainJoin(strUser, strPassword)
' Declare Sub objects and variables
Dim objNetwork, objComputer
Dim strComputer, strDomain, strOrgUnit, strReturnValue, strRetry
Const JOIN_DOMAIN = 1
Const ACCT_CREATE = 2
strDomain = "DOMAIN.COM"
strOrgUnit = "OU=" & GetSystemVariable("Dept") & ";OU=OU;DC=DC;DC=COM"
' Lookup the name of the computer
Set objNetwork = CreateObject("WScript.Network")
strComputer = objNetwork.ComputerName
' Pause the script for 10 seconds before attempting to join the domain
Wscript.Sleep(10000)
Set objComputer = GetObject("winmgmts:{impersonationLevel=Impersonate}!\\" & _
strComputer & "\root\cimv2:Win32_ComputerSystem.Name='" & _
strComputer & "'")
' Join the domain
strReturnValue = objComputer.JoinDomainOrWorkGroup(strDomain, strPassword, _
strDomain & "\" & strUser, strOrgUnit, JOIN_DOMAIN + ACCT_CREATE)
End Sub
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Yes. Most of the cases this would be because of repository damage.
You can do wbemtest on that machine.
Start->Run->wbemtest
Then click on connect
You can do wbemtest on that machine.
Start->Run->wbemtest
Then click on connect
ASKER
Okay. Reimaged the machine and tried your first recommendation prior to executing the scripts. No change.
I'm not sure what you would like me to do with the wbemtest tool.
I'm not sure what you would like me to do with the wbemtest tool.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Would you expect this to happen intermittently if the repository is damaged?