"nerd" <guest@xxxxxx-email.com> wrote in message
news:b4ce69e7b6755dd7e7b97d8188545c6d@xxxxxx-gateway.com...
>
> Hi Friends,
> I m new to progrmamming field and have created a userform that allows
> the user to enter and work according to his needs however as per one of
> my user's request , he asked me if I could give them an option to change
> password . Hence I requets to all genius programers to help me write
> this in VB Script( I am using Excel as the platform )
> I assume a domain user that wants to change his own password. In VBScript
you bind to the user object, then use the ChangePassword method of the
object. You pass the old and new passwords to the method. You need the full
Distinguished Name of the current user to bind to the object, but that can
be retrieved from the ADSystemInfo object. For example, a script that
prompts for required values could be:
==========
Option Explicit
Dim objSysInfo, strUserDN, objUser, strOldPassword, strNewPassword
' Retrieve DN of current user.
Set objSysInfo = CreateObject("ADSystemInfo")
strUserDN = objSysInfo.UserName
' Bind to user object with Distinguished Name.
Set objUser = GetObject("LDAP://" & strUserDN)
' Prompt for old password.
strOldPassword = InputBox("Enter old password")
' Prompt for new password.
strNewPassword = InputBox("Enter new password")
Call objUser.ChangePassword(strOldPassword, strNewPassword)
========
If the user is a local user you must use the WinNT provider (instead of the
LDAP provider). You must bind with the NetBIOS name of the user, but you can
retrieve that from the wshNetwork object. Then the code could be:
=========
Option Explicit
Dim objNetwork, strUser, strComputer, objUser, strOldPassword,
strNewPassword
' Retrieve local user and computer.
Set objNetwork = CreateObject("Wscript.Network")
strUser = objNetwork.UserName
strComputer = objNetwork.ComputerName
' Bind to user object in local SAM account database.
Set objUser = GetObject("WinNT://" & strComputer & "/" & strUser & ",user")
' Prompt for old password.
strOldPassword = InputBox("Enter old password")
' Prompt for new password.
strNewPassword = InputBox("Enter new password")
Call objUser.ChangePassword(strOldPassword, strNewPassword)
--
Richard Mueller
MVP Directory Services
Hilltop Lab -
http://www.rlmueller.net
--