Sub GeEm()
Dim rng1 As Range, c As Range, objUser
Dim intPasswordAge, dtmChangeDate As Date
Set rng1 = Range([q3], Cells(Rows.Count, "Q").End(xlUp))
Application.ScreenUpdating = False
On Error Resume Next
For Each c In rng1
If Replace(c.Value, " ", vbNullString) <> vbNullString Then
If Ping(c.Value) Then
Set objUser = GetObject("WinNT://" & c.Value & "/administrator")
intPasswordAge = objUser.PasswordAge
intPasswordAge = intPasswordAge * -1
dtmChangeDate = DateAdd("s", intPasswordAge, Now)
If objUser Is Nothing Then
Cells(c.Row, "DE") = "Permission error"
Else
Cells(c.Row, "DE") = Format(dtmChangeDate, "dd-mmm-yyyy")
End If
Set objUser = Nothing
Else
Cells(c.Row, "DE") = "off"
End If
End If
Next
Application.ScreenUpdating = True
End Sub
Function Ping(strComputer)
Dim objShell, boolCode
Set objShell = CreateObject("WScript.Shell")
boolCode = objShell.Run("Ping -n 1 -w 300 " & strComputer, 0, True)
If boolCode = 0 Then
Ping = True
Else
Ping = False
End If
End Function
|