1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
| 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
Dim objWMI : Set objWMI = GetObject("WinMGMTS://./Root/CIMv2")
Dim objNetwork : Set objNetwork = CreateObject("WScript.Network")
Dim colBIOS : Set colBIOS = objWMI.ExecQuery("Select * from Win32_BIOS")
Dim colComputers : Set colComputers = objWMI.ExecQuery ("Select Name from Win32_ComputerSystem")
Sub Window_Onload()
Center_HTA 500, 380
Get_Computer_Info()
End Sub
Sub Center_HTA( widthX, heightY )
self.ResizeTo widthX, heightY
self.MoveTo (screen.Width - widthX)/2, (screen.Height - heightY)/2
End Sub
Sub HTASleep(intSeconds)
Dim strCommand
strCommand = "%COMSPEC% /c ping -n " & 1 + intSeconds & " 127.0.0.1>nul"
objWSHShell.Run strCommand, 0, True
End Sub
Sub Clear_Form()
Location.Reload(True)
End Sub
Sub HTA_Close()
self.close()
End Sub
Sub Get_Computer_Info()
For Each objComputer In objWMI.InstancesOf("Win32_ComputerSystem")
strComputer = UCase(objComputer.Name)
Next
td_ComputerName.InnerText = strComputer
End Sub
Sub btn_FixIt_OnClick()
If txt_username.Value = "" Then
MsgBox "Please enter a username."
txt_username.Focus
Exit Sub
End If
If txt_password.value = "" Then
MsgBox "Please enter a password."
txt_password.Focus
Exit Sub
End If
strDomain = "test.locall"
strUser = "test\franck"
strPassword = "mdp456789"
Set objNetwork = CreateObject("WScript.Network")
strComputer = objNetwork.ComputerName
Set objWMIService = GetObject ("winmgmts:" & "!\\" & strComputer & "\root\cimv2")
Set colAdapters = objWMIService.ExecQuery ("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled = True")
title = "Join computer to domain"
message = "Please enter computer name. Leave blank or press cancel to quit." & vbCrLf & vbCrLf & "Generated name: " & generatedName
newComputerName = Trim(txt_Rename.value)
If newComputerName = "" Then
Wscript.quit
End If
areYousure = MsgBox("Are you sure you want to add computer to domain with name:" & vbCrLf & vbCrLf & newComputerName, vbYesNo + vbQuestion,"Add computer to domain")
If areYouSure = "7" Then
MsgBox "Exiting script.",vbInformation
Wscript.quit
End If
Set objComputer = GetObject("winmgmts:{impersonationLevel=Impersonate}!\\" & _
strComputer & "\root\cimv2:Win32_ComputerSystem.Name='" & _
strComputer & "'")
ReturnValue = objComputer.JoinDomainOrWorkGroup(strDomain, strPassword, strDomain & "\" & strUser, _
JOIN_DOMAIN + ACCT_CREATE)
If ReturnValue = 1326 Then
MsgBox "Logon failure, user or pass"
ElseIf ReturnValue = 0 Then
MsgBox "Computer added to domain under old name without error. proceeding to change computer name. "
ElseIf ReturnValue = 5 Then
MsgBox "Access is denied. Run from an elevated command prompt."
ElseIf ReturnValue = 87 Then
MsgBox "The parameter is incorrect."
ElseIf ReturnValue = 110 Then
MsgBox "The system cannot open the specified object."
ElseIf ReturnValue = 1323 Then
MsgBox "Unable to update password."
ElseIf ReturnValue = 1355 Then
MsgBox "The specified domain does not exist or could not be contacted."
ElseIf ReturnValue = 2224 Then
MsgBox "The account already exists."
ElseIf ReturnValue = 2691 Then
title = "Error Computer is already on doamin"
message = "Please enter new computer name." & vbCrLf & vbCrLf & "Generated name: " & generatedName
ElseIf ReturnValue = 2692 Then
MsgBox "The machine is not currently joined to the domain."
End If
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colComputers = objWMIService.ExecQuery _
("Select * from Win32_ComputerSystem")
For Each objComputer in colComputers
MsgBox "About to rename computer to: " & newComputername
ReturnValue = objComputer.Rename(newComputerName, strPassword, strUser)
If ReturnValue = 0 Then
MsgBox "Computer renamed correctly."
HTA_Close()
Else MsgBox "Eror changing computer name. Error code: " & ReturnValue
End If
Next
End Sub |
Partager