Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Password Changing Script 2

Status
Not open for further replies.

ckugo

IS-IT--Management
Joined
Jan 6, 2004
Messages
165
Location
US
I am trying to change users passwords with the sample script that is in the microsoft script center. This one:


Set objUser = GetObject _
("LDAP://cn=myerken,ou=management,dc=fabrikam,dc=com")
objUser.ChangePassword "i5A2sj*!", "jl3R86df"

Everyone I run this I get an error that says:

A referral was sent to the server.
code: 8007202b
source: (null)

in the script, what do the two "dc"'s mean? I figured they stood for domain controller, but why is there two??

Any help is greatly apprecitated.
Thanks in Advance,

Chris
 
DC stands for DomainComponent, OU stands for OrganizationalUnit and CN is for CommonName. If your active Directory domain is CompanyOne.MainCompany.Local then the Ldap path would be LDAP://DC=CompanyOne,DC=MainCompany,DC=Local

a user in the Accounting OU at the root of the domain would have the Ldap path of.

LDAP://cn=User,OU=Accounting,DC=CompanyOne,DC=MainCompany,DC=Local
 
Thank you for the help, but I still did not have any luck.
This is what I am trying to do. I am trying to pass the username and password as variables. Is that even possible? Anyway, please take a look and see what you think.

option explicit
dim strname, stroldpwd,strnewpwd
strname = inputbox("Type in your username")
stroldpwd = inputbox("Type in your old password")
strnewpwd = inputbox("Type in your new password")
Set objUser = GetObject("LDAP://cn=strname,ou=accounting,dc=machinename,dc=domain,dc=local")
objUser.ChangePassword stroldpwd, strnewpwd

Now when I try to run it I get a different message. It says:

Error: There is no such object on the server
code: 80072030
source: (null)
 
Try this:
Set objUser = GetObject("LDAP://cn=" & strname & ",ou=accounting,dc=machinename,dc=domain,dc=local")


Hope This Help
PH.
 
PH,

When I try that I get a compliation error.

expected ')'

Thanks
 
Replace this line

Set objUser = GetObject("LDAP://cn=strname,ou=accounting,dc=machinename,dc=domain,dc=local")

with this:

Set objUser = GetObject("LDAP://cn=" & strname & ",ou=accounting,dc=machinename,dc=domain,dc=local")
 
Can you post the code you are usign so we can see where you may have goofed? The context that PHV gave you is correct. Most likely you either have your LDAP path wrong for your environment or you have a typo somewhere.
 
I am still getting the same error message as before. The one saying There is no such object on the server.

Can the OU have spaces in the name?? Mine does and I am starting to think that that might have something to do with it.

Thanks
 
This is an script I wrote a long time ago, feel free to try it, like your script above, it requires the user's current password. Also, I am using the WinNT provider instead of the Ldap Provider.

'Script Starts Here.
Dim User, Username, Domain, InitialMsg, SecondMsg

'Bind to Active Directory System Info
Set AdsSysteminfo = CreateObject("adsysteminfo")
UserDomain=AdsSystemInfo.DomainShortName

'InitialMsg="Please enter the username that needs the password changed!"
'SecondMsg="Sorry, but you must enter a username to continue!" &vbCr &"Or press Cancel to quit." &vbCr
'UserName=GetPassword(InitialMsg)
AskUser

Sub AskUser
On Error Resume Next
Set User=GetObject("WinNT://" &Userdomain &"/" &Username & ",user")
If err.number<>0 Then
InitialMsg=&quot;Please enter a valid username that needs the password changed!&quot;
SecondMsg=&quot;Sorry, but you must enter a username to continue!&quot; &vbCr &&quot;Or press Cancel to quit.&quot; &vbCr
UserName=GetPassword(InitialMsg)
AskUser
wscript.quit
End If
InitialMsg=UserName &Vbcr &&quot;Please enter your current password&quot;
SecondMsg=&quot;Sorry you must enter a password.&quot; &vbCr &&quot;Or press Cancel to quit.&quot; &vbCr
OldPassword=GetPassword(InitialMsg)

InitialMsg=UserName &Vbcr &&quot;Please enter your new password&quot;
NewPassword1=GetPassword(InitialMsg)

InitialMsg=UserName &Vbcr &&quot;Please verify the new password&quot;
NewPassword2=GetPassword(InitialMsg)

If NewPassword1=NewPassword2 Then
Call User.ChangePassword(OldPassword,NewPassword1)
Select Case Err.number
case 0
msgbox &quot;Password Changed Successfully&quot;
wscript.quit
Case -2147024810
msgbox &quot;Password Not Changed!&quot; &vbCr &&quot; An error occurred, Please try again.&quot; &vbCr &&quot;The specific error number is:&quot; & err.number _
&Vbcr &&quot;The error message is: The specified network password is not correct.&quot;
Case -2147022651
msgbox &quot;Password Not Changed!&quot; &vbCr &&quot;An Error occurred, Please try again.&quot; &vbCr &&quot;The specific Error number Is:&quot; & err.number _
&Vbcr &&quot;The error message is: The password does not meet the password policy requirements. Check the minimum password length, &quot; _
& &quot;password complexity and password history requirements.&quot;
Case Else
msgbox &quot;Password Not Changed!&quot; &vbCr &&quot; An error occurred, Please try again.&quot; &vbCr &&quot;The specific error number is:&quot; & err.number _
& &quot;A specific error message is not available.&quot;
End Select
err.clear
AskUser
Else
Msgbox &quot;Sorry, the new password entries do not match!&quot; &vbCr &&quot;Please try again&quot;
AskUser
End If
End Sub


Function Getpassword(ask)

getpassword= InputBOx(ask,&quot;Password entry form&quot;)
If getpassword = vbEmpty Then WScript.Quit
If getpassword = &quot;&quot; Then getpassword=GetPassword(SecondMSg &initialmsg)

end function
 
Wow, thank you very much. That is a very nice script. I don't mean to get greedy here but I have to ask. Is there some way to see '*' instead of the password being typed??

Also, is there any way to send the variables that are typed to a txt file or database??
 
For masking the password input: thread329-637366

Hope This Help
PH.
 
I want to thank everyone for their help, it is greatly appreciated.

Does anyone have any ideas on how to write the variables to a text file?

Thanks,

Chris
 
You may play with the FileSystemObject (fso) object.
Do a keyword search in this forum for fso write to get a LOT of examples.

Hope This Help
PH.
 
Set fso = CreateObject(&quot;Scripting.FileSystemObject&quot;)

report = &quot;Sample Text&quot;

Set ts = fso.CreateTextFile (&quot;c:\test.txt&quot;, ForWriting)

ts.write report
 
Mark,

Thank you for the wonderful tip. I was able to get that working just fine. But it gets a little bit more complicated.

What needs to happen is that data needs to be written to the log file multiple times without erasing anything.
Example:
User1 changes password at 8:30a.m.
-Info gets written to txt file
User2 changes password at 11:00a.m.
-Info gets written to same text file

Log looks like:
User1 password
User2 password
etc....
 
Just open your file ForAppending (8)

Hope This Help
PH.
 
CONST ForAppending = 8

Set fso = CreateObject(&quot;Scripting.FileSystemObject&quot;)

report = &quot;Sample Text&quot;

Set ts = fso.CreateTextFile (&quot;c:\test.txt&quot;, ForAppending)

ts.write report
 
I am sorry to be so new to this. You guys have been a great help. But how do I open it for Appending??

Thanks again
 
Read the post above your last one. I changed the script for you to open it for appending.
 
This changes the info in the log file, but it does not list the information. By doing that the log file only shows 1 entry (which is different everytime), instead of 2 or 3, etc..

It is changes the info though.

Thanks again
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top