Re: winnt provider and lastlogin using vbscript
- From: "Richard Mueller [MVP]" <rlmueller-nospam@xxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 30 Jul 2008 11:38:43 -0500
"Richard Mueller [MVP]" <rlmueller-nospam@xxxxxxxxxxxxxxxxxxxx> wrote in
message news:%2321OkDm8IHA.4924@xxxxxxxxxxxxxxxxxxxxxxx
<awrightus@xxxxxxxxxxx> wrote in message
news:1458b1bf-feb4-4074-a313-9ab47eb14458@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
I have a Windows 2003 workgroup server. No AD, domain, etc. In my
login script, using vbscript, I need to be able to tell the user when
they last logged on. I thought I had this licked by using the winnt
provider and the lastlogin attribute. However, during the login
process, it appears as if lastlogin has already been updated to the
current time, completely having overwritten what I was trying to
capture. During the user login process, is there any other attribute
that I can grab that will tell me when the user last logged in?
Thanks.
I noticed the same thing some time ago. There is no other attribute you
can use. The only thing I can think if is to save the date/time for future
use. Since this is a local account, you could save the information in a
text somewhere on the computer everyone has access to, perhaps in a file
named after the username.
--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--
A quick VBScript example below. There are many other ways, but all involve
saving the logon date/time yourself somewhere the user has permissions:
=========
Option Explicit
Dim objNetwork, strName, strFile, objFSO, objFile
Dim strLast
Const ForReading = 1
' Retrieve user name.
Set objNetwork = CreateObject("Wscript.Network")
strName = objNetwork.UserName
' Specify local log file for this user.
strFile = "c:\scripts\" & strName & ".log"
Set objFSO = CreateObject("Scripting.FileSystemObject")
' Read the file if it exists.
' Trap the error if it does not exist.
On Error Resume Next
Set objFile = objFSO.OpenTextFile(strFile, ForReading)
If (Err.Number = 0) Then
On Error GoTo 0
' Read the last logon date/time and display.
strLast = objFile.ReadLine
objFile.Close
Call MsgBox("You last logged on at " & strLast)
End If
On Error GoTo 0
' Save the new last logon date/time in the log file.
Set objFile = objFSO.CreateTextFile(strFile, True)
objFile.WriteLine CStr(Now())
objFile.Close
--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--
.
- References:
- winnt provider and lastlogin using vbscript
- From: awrightus@xxxxxxxxxxx
- Re: winnt provider and lastlogin using vbscript
- From: Richard Mueller [MVP]
- winnt provider and lastlogin using vbscript
- Prev by Date: Re: winnt provider and lastlogin using vbscript
- Next by Date: Script to retrieve file versions
- Previous by thread: Re: winnt provider and lastlogin using vbscript
- Next by thread: Re: winnt provider and lastlogin using vbscript
- Index(es):
Relevant Pages
|