Bonjour j'ai actuellement un script vbs qui permet de changer le mot de passe de session pour un utilisateur donné.
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.
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
Cela donne ça :
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
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>
Partager