Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 433
  • Last Modified:

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

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

0
bsharath
Asked:
bsharath
1 Solution
 
Krys_KCommented:
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

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now