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

Enumerating Login times

Status
Not open for further replies.

CORT1

MIS
Sep 4, 2002
12
0
0
US
I have a script that I use that tells me when and if a user logged on.
The script works fine if I use an input box and only one user it gives me the correct information. However if I run the script reading from a text file, some of the users get an n/a but if I run the same user using the inputbox it gives me the accurate information. This is not isolated to all users, some accounts come out accurate. Please help
Here is the script
Thanks
____________________________________________________________
On Error Resume Next
Dim objFSO,objFile,strLine
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\Documents and Settings\me\Desktop\allnames.txt",1)
Do Until objFile.AtEndOfStream
strLine = objFile.ReadLine
Set myUser = GetObject("WinNT://cort.com" & "/" & strLine & ",user")
If Err <> 0 Then
WScript.Echo strLine & &quot; &quot; & &quot;n/a&quot;
Err.Clear
Else
WScript.echo strLine & &quot; &quot; & myuser.LastLogin
End If
Loop
objFile.close
 
Whether strLine is populated thru an inputbox or from text read-in from a file is irrelevant, as long as strLine contains the same value both ways.

Where you echo &quot;n/a&quot;, add Err.Description to get a better idea of what's going on.

FYI, LastLogin/LastLogoff are not replicated properties, ie, they are locally stored properties specific to the domain controllers. Thus if you query the PDC you'll get one value, and if you query the BDC you'll get another, most likely, different value.

If you want the real LastLogin value for each user, you'll need to cycle thru the DCs and accept the last date value.

Jon Hawkins
 
Thanks for the help, I understand that strLine contains the same value weather I have it as an input box or reading from a text file and I have already tried using err.description as well as err.number but I get errors that say not found on accounts that give me the accurate information from an inputbox. I can get the correct information as well if I just run on error resume next and forget the error response all together. I also am aware that the information is diferent on each DC I have already accounted for that. Obviously I know that there is something going on with the error checking, this I connot figure out.
 
on error resume next
set wshshell=wscript.createobject(&quot;Wscript.shell&quot;)
Set dom = GetObject(&quot;WinNT://idghead&quot;)
set FSO = CreateObject(&quot;scripting.FileSystemObject&quot;)
set myFile = fso.createtextfile(&quot;users.txt&quot;, true)
dom.Filter = Array(&quot;user&quot;)
For each usr in dom
myFile.WriteLine(&quot;Full Name: &quot;&usr.fullname&&quot;&quot;)
myfile.writeline(&quot;Last Login : &quot;&usr.lastlogin&&quot;&quot;)
Next

This will create a text file that should contain all the user names and last login times. You will need the ADSI client if you are running it from a Windows 95/98 PC.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top