IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

VBScript Discussion :

Probleme integration poste a un domaine objComputer.JoinDomainOrWorkGroup


Sujet :

VBScript

  1. #1
    Candidat au Club
    Homme Profil pro
    Assistant aux utilisateurs
    Inscrit en
    Mars 2014
    Messages
    3
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 39
    Localisation : France

    Informations professionnelles :
    Activité : Assistant aux utilisateurs

    Informations forums :
    Inscription : Mars 2014
    Messages : 3
    Points : 4
    Points
    4
    Par défaut Probleme integration poste a un domaine objComputer.JoinDomainOrWorkGroup
    Bonjour a tous !
    Dans le script suivant, qui ajoute une machine a l'annuaire et le joint au domaine qui fonctionne presque parfaitement
    je rencontre un petit problème.
    Lors de l'ajout du poste au domaine, celui ci me rajout le groupe test.local dans Groupe de travail au lieu de Domaine ( sur le poste a installer).
    Quelqu'un a une petite idée?

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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

  2. #2
    Membre émérite Avatar de tsuji
    Inscrit en
    Octobre 2011
    Messages
    1 558
    Détails du profil
    Informations forums :
    Inscription : Octobre 2011
    Messages : 1 558
    Points : 2 736
    Points
    2 736
    Par défaut
    La signature de la méthode JoinDomainOrWorkgroup n'est pas tout à fait respectée dans les lignes #80-81 : essayez plutôt comme ça.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    ReturnValue = objComputer.JoinDomainOrWorkGroup(strDomain, strPassword, strDomain & "\" & strUser,  _
    null, JOIN_DOMAIN + ACCT_CREATE)

Discussions similaires

  1. [WS 2008 R2] probleme pour joindre un poste client au domaine ?
    Par delphino7 dans le forum Windows Serveur
    Réponses: 7
    Dernier message: 03/04/2014, 15h23
  2. Integration postes distants au domaine en powershell
    Par sebos21 dans le forum Scripts/Batch
    Réponses: 0
    Dernier message: 26/09/2011, 17h02
  3. probleme d'integration poste NT dans domaine 2003
    Par gretch dans le forum Windows Serveur
    Réponses: 5
    Dernier message: 13/01/2008, 20h12
  4. Probleme Methode POST
    Par pidu dans le forum Général JavaScript
    Réponses: 6
    Dernier message: 06/02/2006, 17h33
  5. probleme integrer un wave
    Par BigBarbare dans le forum VB 6 et antérieur
    Réponses: 4
    Dernier message: 26/01/2005, 18h47

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo