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 :

VBScript dans HTMLpour modifier mot de passe AD


Sujet :

VBScript

  1. #1
    Nouveau membre du Club
    Homme Profil pro
    Administrateur systèmes et réseaux
    Inscrit en
    Juin 2011
    Messages
    5
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Administrateur systèmes et réseaux
    Secteur : Services de proximité

    Informations forums :
    Inscription : Juin 2011
    Messages : 5
    Par défaut VBScript dans HTMLpour modifier mot de passe AD
    Bonjour j'ai actuellement un script vbs qui permet de changer le mot de passe de session pour un utilisateur donné.

    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
     
    option explicit
     
    const strLDAPRoot = "LDAP://Mondomaine"
    const intNormalOperation = 0
    const intUserNotFound = 1
    const intCouldNotChangePassword = 2
     
    dim strUserName
    dim strUserOldPassword
    dim strUserNewPassword
    dim strUserDN
     
     
    '**********************************
    'Error handling
    '**********************************
    on error resume next
     
    '**********************************
    'Logic
    '**********************************
    'Get the command line arguments
    select case wscript.arguments.count
     Case 3:
      'Set the variables from the command line
      strUserName = wscript.arguments(0)
      strUserOldPassword = wscript.arguments(1)
      strUserNewPassword = wscript.arguments(2)
     
      'find the distinguished name for this user
      strUserDN = GetUserDistinguishedname(strLDAPRoot, strUserName)
      CheckForError intUserNotFound
     
     case 0:
      'Get the user's login name from the interactive user
      strUserName = inputbox("Quel est votre nom d'utilisateur ?")
     
      'find the distinguished name for this user
      strUserDN = GetUserDistinguishedname(strLDAPRoot, strUserName)
      intUserNotFound
     
      if strUserDN <> "" then  
       'if the query returned a distinguished name, then ask for a password  
       strUserOldPassword = inputbox("Quel est votre ancien mot de passe ?")
     
       'if the query returned a distinguished name, then ask for a password  
       strUserNewPassword = inputbox("QUel est votre mot de passe souhaité ?")
      else
       'the query did not return a distinguished name (user was not found)
       msgbox "That user was not found in Active Directory.  Please check the login name and try again."
      end if
     
     Case Else:
      'the wrong number of parameters were supplied on the command line.  Notify the user
      msgbox "Usage: SetPassword.vbs <username> <old password> <new password>" & vbcrlf & vbcrlf & "You can also use SetPassword without any parameters for interactive mode."
    end select
     
    'At this point, terminate the program execution if we don't have a distinguished name for the user account
    if strUserDN <> "" then
     ChangeUserPassword strUserDN, strUserOldPassword, strUserNewPassword
     CheckForError intCouldNotChangePassword
     
     'quit and return a successful errorlevel
     wscript.quit intNormalOperation
    else
     'quit and return errorlevel indicating the user was not found
     wscript.quit intUserNotFound
    end if
     
     
    '**********************************
    'Functions
    '**********************************
    Function GetUserDistinguishedName(strLDAPRoot, strSamAccountName)
     dim objConnection
     dim objCommand
     dim objRecordset
     
     Set objConnection = CreateObject("ADODB.Connection")
     objConnection.Open "Provider=ADsDSOObject;"
     
     Set objCommand = CreateObject("ADODB.Command")
     objCommand.ActiveConnection = objConnection
     objCommand.CommandText = "SELECT distinguishedName FROM '" & strLDAPRoot & "' WHERE objectCategory='user' AND sAMAccountName='" & strSamAccountName & "'"
     Set objRecordSet = objCommand.Execute
     
     if Not objRecordset.EOF then
      GetUserDistinguishedName = objRecordset.Fields("distinguishedname")
     end if
     
     objConnection.Close
    End Function
     
    Function GetUserLastPasswordChange(strUserDN)
     dim objUser
     
     Set objUser = GetObject("LDAP://" & strUserDN)
     GetUserLastPasswordChange = objUser.PasswordLastChanged
    End Function
     
    Function ChangeUserPassword(strUserDN, strOldPassword, strNewPassword)
     dim objUser
     
     Set objUser = GetObject("LDAP://" & strUserDN)
     objUser.ChangePassword strOldPassword, strNewPassword
     
    End Function
     
    Sub CheckForError(intErrorCondition)
     if err.number <> 0 then
      wscript.quit intErrorCondition
     end if
    end sub
    J'aimerais intégrer ce script dans du HTML, ce qui me permettrai d'avoir une page web de modification de mot de passe en cliquant sur un bouton.
    Cela donne ça :

    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
    124
    125
    126
    <HTML>
    <HEAD>
    <TITLE>New Page</TITLE>
    <FORM NAME="Form1">
       <INPUT TYPE="Button" NAME="test" VALUE="Click">
       <SCRIPT FOR="test" EVENT="onClick" LANGUAGE="VBScript">
    option explicit
     
    const strLDAPRoot = "LDAP://Mondomaine"
    const intNormalOperation = 0
    const intUserNotFound = 1
    const intCouldNotChangePassword = 2
     
    dim strUserName
    dim strUserOldPassword
    dim strUserNewPassword
    dim strUserDN
     
     
    '**********************************
    'Error handling
    '**********************************
    on error resume next
     
    '**********************************
    'Logic
    '**********************************
    'Get the command line arguments
    select case wscript.arguments.count
     Case 3:
      'Set the variables from the command line
      strUserName = wscript.arguments(0)
      strUserOldPassword = wscript.arguments(1)
      strUserNewPassword = wscript.arguments(2)
     
      'find the distinguished name for this user
      strUserDN = GetUserDistinguishedname(strLDAPRoot, strUserName)
      CheckForError intUserNotFound
     
     case 0:
      'Get the user's login name from the interactive user
      strUserName = inputbox("Quel est votre nom d'utilisateur ?")
     
      'find the distinguished name for this user
      strUserDN = GetUserDistinguishedname(strLDAPRoot, strUserName)
      intUserNotFound
     
      if strUserDN <> "" then  
       'if the query returned a distinguished name, then ask for a password  
       strUserOldPassword = inputbox("Quel est votre ancien mot de passe ?")
     
       'if the query returned a distinguished name, then ask for a password  
       strUserNewPassword = inputbox("QUel est votre mot de passe souhaité ?")
      else
       'the query did not return a distinguished name (user was not found)
       msgbox "That user was not found in Active Directory.  Please check the login name and try again."
      end if
     
     Case Else:
      'the wrong number of parameters were supplied on the command line.  Notify the user
      msgbox "Usage: SetPassword.vbs <username> <old password> <new password>" & vbcrlf & vbcrlf & "You can also use SetPassword without any parameters for interactive mode."
    end select
     
    'At this point, terminate the program execution if we don't have a distinguished name for the user account
    if strUserDN <> "" then
     ChangeUserPassword strUserDN, strUserOldPassword, strUserNewPassword
     CheckForError intCouldNotChangePassword
     
     'quit and return a successful errorlevel
     wscript.quit intNormalOperation
    else
     'quit and return errorlevel indicating the user was not found
     wscript.quit intUserNotFound
    end if
     
     
    '**********************************
    'Functions
    '**********************************
    Function GetUserDistinguishedName(strLDAPRoot, strSamAccountName)
     dim objConnection
     dim objCommand
     dim objRecordset
     
     Set objConnection = CreateObject("ADODB.Connection")
     objConnection.Open "Provider=ADsDSOObject;"
     
     Set objCommand = CreateObject("ADODB.Command")
     objCommand.ActiveConnection = objConnection
     objCommand.CommandText = "SELECT distinguishedName FROM '" & strLDAPRoot & "' WHERE objectCategory='user' AND sAMAccountName='" & strSamAccountName & "'"
     Set objRecordSet = objCommand.Execute
     
     if Not objRecordset.EOF then
      GetUserDistinguishedName = objRecordset.Fields("distinguishedname")
     end if
     
     objConnection.Close
    End Function
     
    Function GetUserLastPasswordChange(strUserDN)
     dim objUser
     
     Set objUser = GetObject("LDAP://" & strUserDN)
     GetUserLastPasswordChange = objUser.PasswordLastChanged
    End Function
     
    Function ChangeUserPassword(strUserDN, strOldPassword, strNewPassword)
     dim objUser
     
     Set objUser = GetObject("LDAP://" & strUserDN)
     objUser.ChangePassword strOldPassword, strNewPassword
     
    End Function
     
    Sub CheckForError(intErrorCondition)
     if err.number <> 0 then
      wscript.quit intErrorCondition
     end if
    end sub
     
    </SCRIPT>
    </FORM>
    </HEAD>
    <BODY>
     
    </BODY>
    La page web m'indique qu'il y a des erreurs sur la page et le script ne s'execute pas. Pouvez vous m'aider s'il vous plait

  2. #2
    Nouveau membre du Club
    Homme Profil pro
    Administrateur systèmes et réseaux
    Inscrit en
    Juin 2011
    Messages
    5
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Administrateur systèmes et réseaux
    Secteur : Services de proximité

    Informations forums :
    Inscription : Juin 2011
    Messages : 5
    Par défaut
    mon script test.vbs fonctionne donc quand je lance manuellement, je viens d'essayer de l'appeler avec la balise
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    <script src="test.vbs" type="text/vbscript">
    Et rien ne se passe. Pourtant cette balise fonctionne avec un script basique de type msgbox ""

Discussions similaires

  1. Modifier Mot-de-passe Utilisateur
    Par Le_Suisse dans le forum Bases de données
    Réponses: 0
    Dernier message: 05/11/2008, 11h48
  2. User Form : Peut-on cacher ce qu'on écrit dans une zone (Mot de passe)
    Par Godzestla dans le forum Macros et VBA Excel
    Réponses: 2
    Dernier message: 09/09/2008, 11h22
  3. Réponses: 1
    Dernier message: 30/07/2008, 23h44
  4. Modifier mot de passe administrateur
    Par elghadi_mohamed dans le forum MS SQL Server
    Réponses: 7
    Dernier message: 12/11/2007, 04h52
  5. modifier mot de passe de la base de donnée
    Par zut94 dans le forum Access
    Réponses: 9
    Dernier message: 28/02/2006, 11h36

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