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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Check local Admin password

Status
Not open for further replies.

greg0303

Technical User
May 5, 2006
94
CA
I am trying to write a script that will go through a list of computers and check that the local admin password is what it should be set to. I am trying to use .ChangePassword and resetting the password to itself so I know that's the right password, if its not then it should display Bad Password. However when testing on a machine I am certain the password is right I am still gettting an error '-2147023569'. Any ideas?

Code:
oDomain = "TestComputer"
oUser = "Administrator"
oPassword = "123456"


Set objUser = GetObject("WinNT://" & oDomain & "/" & oUser & ", user" )

if err.number <> 0 then
msgbox "Login Error"
end if

on error resume next

objUser.ChangePassword oPassword, oPassword
if err.number <> 0 then
msgbox "BAD PASSWORD!"
msgbox err.number
else
msgbox "Good Password"
end if
 
That's likly it, thanks.
Is there a better way to verify a password is correct?
 
try this:

'#####################################
'
' Change Local Administrator Name and password on a computer
'
' To use:
' 1. change the snewuser to the name of the administrator
' 2. Change the newpwd to a new password
' 3. For each OU or CN that contains a computer you want to change, modify the LDAP:// in the CWDPWD, you can
' Run this against as many OUs that you want, just have multiple CWDPWD lines
' 4. Change the my.company.com to the FQDN of your domain where the computer will sit. (don't forget to put the . before the domain name
'
'#####################################


Dim sUserSID, oWshNetwork, oUserAccount,snewuser,newpwd

Set oWshNetwork = CreateObject("WScript.Network")
snewuser = "NewAdminName"
newpwd = "NewPassword"

Call CWDPWD ("LDAP://ou=servers,dc=My,dc=Domain,dc=com",".my.company.com")


SUB CWDPWD (List,Domain)
on error resume next
'-----Get the servername
set serverlist = getobject (List)

'-----For Each Server
for each server in serverlist

'-----Set the Computer Name
sComputerName = server.cn
wscript.echo sComputerName&Domain


'-----Turn on Error Checking
'on error resume next

'-----Get AminsitratorName
Set oUserAccounts = GetObject( "winmgmts:{impersonationLevel=impersonate}!//" & sComputerName & "/root/cimv2").ExecQuery( "Select Name, SID from Win32_UserAccount WHERE Domain = '" & sComputerName & "'")

For Each oUserAccount In oUserAccounts
If Left(oUserAccount.SID, 9) = "S-1-5-21-" And Right(oUserAccount.SID, 4) = "-500" Then
AdministratorName = oUserAccount.Name
Exit For
End if
Next

'-----Bind
Set oUSer = GetObject("WinNT://"&sComputerName&Domain&"/"&AdministratorName &",user")
Set oComputer = GetObject("WinNT://"&sComputerName&Domain)

'------Name
Set oNewUser = oComputer.MoveHere(oUser.ADsPath, sNewUser)

'------Password
oUSer.setpassword newpwd
oUSer.SetInfo

'------Null Everything OUt
Set oWshNetwork = nothing
Set UserObj = Nothing
set uouserAccounts=nothing
administratorName=null
Set oUser = nothing
Set oComputer = nothing

NEXT


on error goto 0
end sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top