We help IT Professionals succeed at work.

Find the local Administrator password changed date.Script is not acurate.

Medium Priority
463 Views
Last Modified: 2012-05-06
Hi,

Find the local Administrator password changed date.Script is not acurate.
Script works but gets the dates for machines that are timed out also. So i feel its not acurate.

Can anyone help me to check why it does not get the exact date.

Regards
Sharath

Const ForAppending = 8
Const ForReading = 1
 On Error Resume Next
Set fso=CreateObject("Scripting.FileSystemObject")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.CreateTextFile("C:\pass_changed.txt")
Set objNetwork = CreateObject("Wscript.Network")
 
Set objFile=fso.OpenTextFile("C:\computers.txt", ForReading)
 
Do Until objFile.atEndofStream
     strComputer = objFile.ReadLine
    
Set objUser = GetObject("WinNT://" & strComputer & "/administrator")
 
intPasswordAge = objUser.PasswordAge
intPasswordAge = intPasswordAge * -1 
dtmChangeDate = DateAdd("s", intPasswordAge, Now)
 
objTextFile.WriteLine "Password for " & strComputer & " was last changed: " & dtmChangeDate
Loop

Open in new window

Comment
Watch Question

Commented:
Hi there

I have added a check to see if a computer is online / accessible first, then only get the passwor last changed on those computers we can connect to and log the ones we cannot connect to.

Hope this helps

Regards
Krystian
	Call PswdLastChanged
 
Sub PswdLastChanged
 
	Const ForAppending = 8
	Const ForReading = 1
 
	 On Error Resume Next
 
	Set fso=CreateObject("Scripting.FileSystemObject")
	Set objFSO = CreateObject("Scripting.FileSystemObject")
	Set objTextFile = objFSO.CreateTextFile("C:\pass_changed.txt")
	Set objNetwork = CreateObject("Wscript.Network")
	 
	Set objFile = fso.OpenTextFile("C:\computers.txt", ForReading)
	 
	Do Until objFile.atEndofStream
	     strComputer = objFile.ReadLine
 
		If Reachable(strComputer) = True Then 
			Set objUser = GetObject("WinNT://" & strComputer & "/administrator")
			 
				intPasswordAge = objUser.PasswordAge
				intPasswordAge = intPasswordAge * -1 
				dtmChangeDate = DateAdd("s", intPasswordAge, Now)
				 
				objTextFile.WriteLine "Password for " & strComputer & " was last changed: " & dtmChangeDate
		Else
			objTextFile.WriteLine "Computer not accessible: " & strComputer
		
		End If 
	Loop
 
End Sub
 
 
Private Function Reachable(strComputer)
' Version 1.0
' Written By Krystian Karia
' Dated 11-Mar-2005
 
' Checks if a conputer is online / accessible
 
	On Error Resume Next
 
	Dim objPing, objStatus
 
	Set objPing = GetObject("winmgmts:{impersonationLevel=impersonate}")._
		ExecQuery("select * from Win32_PingStatus where address = '" & strComputer & "'")
 
	For Each objStatus in objPing
		If IsNull(objStatus.StatusCode) Or objStatus.Statuscode <> 0 Then
			Reachable = False 'if computer is unreacable, return false
		Else
			Reachable = True 'if computer is reachable, return True
		End If
	Next
 
End Function 'Reachable

Open in new window

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.