running a join domain vbs inside an HTA error

Anything VBScript-related, including Windows Script Host, WMI, ADSI, and more.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 11 years and 11 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
fannonland
Posts: 2
Last visit: Thu Mar 29, 2012 12:24 pm

running a join domain vbs inside an HTA error

Post by fannonland »

So, I just want to start out by saying I am working with a huge hta file that runs a ton of VBScripts inside it. We are talking maybe....2000 lines of code. So my question won't be easy to explain and I will do my best to give everyone the answers they require. First off, here is my error message that I get during my "Join Computer to Domain"

----------------------------------------
An error has occured in the script on this page
Line: 898 (highlighted in Red below)
Char:2
Error: could not complete the operation due to error 80041002.
-----------------------------------------

At the start of my hta I have input boxes where the user is able to enter in the name of a computer. Which is where I get the strcomputername.value

Code: Select all

blnAnswer = window.confirm("Are you sure you want to continue? " & vbcrlf & vbcrlf & "Computer Name Will Become: " & vbcrlf & strComputerName.value)

Line :898 is in bold below which is where my hta stops and throws an error. Anyone have any ideas?

Code: Select all

Function JoinRETALDomain
  Task4StatusRed.style.visibility="hidden"
   Task4StatusProcessing.style.visibility="visible"
   HTASleep(1)

 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
 Const wshOk = 6
 Const wshYesNoDialog = 4
 Const wshQuestionMark = 32
 
 strDomain = "big.domainname.com"
 strUser = "administrator"
 strPassword = "bestpasswordever"
 strOU = "OU=ThinClients,OU=Computers,DC=domain,DC=com"
 
 Set objNetwork = CreateObject("WScript.Network")
 strComputer = strComputerName.value
 Set objComputer = GetObject("winmgmts:" _
 & "{impersonationLevel=Impersonate,authenticationLevel=Pkt}!" & _
 strComputer & "rootcimv2:Win32_ComputerSystem.Name='" & _
 strComputer & "'")
 ReturnValue = objComputer.JoinDomainOrWorkGroup(strDomain, _
 strPassword, strDomain & "" & strUser, strOU, _
 JOIN_DOMAIN + ACCT_CREATE)
        
If ReturnValue = 0 Then
    Message1 = objShell.Popup("Computer added to domain under old name without error. proceeding to change computer name. ")
Else
    Message2 = objShell.Popup("Computer not added to domain successfully. Return value: " & ReturnValue)
End If
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!" & strComputer & "rootcimv2")
Set colComputers = objWMIService.ExecQuery _
    ("Select * from Win32_ComputerSystem")

For Each objComputer in colComputers
    Message3 = objShell.Popup("About to rename computer to: " & strComputer, 4, "Change Computer Name")
        ErrCode = objComputer.Rename(strComputer, strPassword, strUser)
    If ErrCode = 0 Then
        Message4 = objShell.Popup("Computer renamed correctly.", 4)
    Else
        Message5 = objShell.Popup("Error changing computer name. Error code: " & ErrCode, 4)
    End If
Next
   HTASleep(1)
   Task4StatusProcessing.style.visibility="hidden"
   Task4StatusRed.style.visibility="hidden"
   Task4StatusGreen.style.visibility="visible"
   HTASleep(3) 
  UpdateFireWall
End Function
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

running a join domain vbs inside an HTA error

Post by jvierra »

What is strComputerName?

This is your code:

strComputer = strComputerName.value

This would only work if strComputerName was a textbox.

I suspect that it is not this line that is causing that error.
User avatar
fannonland
Posts: 2
Last visit: Thu Mar 29, 2012 12:24 pm

running a join domain vbs inside an HTA error

Post by fannonland »

"strComputerName.value" is the input from the textbox by the user when the hta starts. I ask what they want to call the computer. Then it goes through a series of 10 steps based on that one text box they entered information.

I honestly have no idea how else to join the domain other than WMI from these XP Embedded machines. What do you suggest?
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

running a join domain vbs inside an HTA error

Post by jvierra »

You cannot impersonate to the local machine with WMI.

Change this line:Set objComputer = GetObject("winmgmts:" _ & "{impersonationLevel=Impersonate,authenticationLevel=Pkt}!" & _ strComputer & "root

To this:
Set objComputer = GetObject("winmgmts:.rootCimV2")Set colComputers = objWMIService.ExecQuery("Select * from Win32_ComputerSystem")

This is the only way to connect to the local system.
This topic is 11 years and 11 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked