Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - winnt provider and lastlogin using vbscript

Reply
 
Old 07-30-2008   #1 (permalink)
awrightus


 
 

winnt provider and lastlogin using vbscript

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.

My System SpecsSystem Spec
Old 07-30-2008   #2 (permalink)
Richard Mueller [MVP]


 
 

Re: winnt provider and lastlogin using vbscript


<awrightus@xxxxxx> wrote in message
news:1458b1bf-feb4-4074-a313-9ab47eb14458@xxxxxx
Quote:

>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
--


My System SpecsSystem Spec
Old 07-30-2008   #3 (permalink)
Richard Mueller [MVP]


 
 

Re: winnt provider and lastlogin using vbscript


"Richard Mueller [MVP]" <rlmueller-nospam@xxxxxx> wrote in
message news:%2321OkDm8IHA.4924@xxxxxx
Quote:

>
> <awrightus@xxxxxx> wrote in message
> news:1458b1bf-feb4-4074-a313-9ab47eb14458@xxxxxx
Quote:

>>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
--


My System SpecsSystem Spec
Old 07-30-2008   #4 (permalink)
Al Dunbar


 
 

Re: winnt provider and lastlogin using vbscript


"Richard Mueller [MVP]" <rlmueller-nospam@xxxxxx> wrote in
message news:%2321OkDm8IHA.4924@xxxxxx
Quote:

>
> <awrightus@xxxxxx> wrote in message
> news:1458b1bf-feb4-4074-a313-9ab47eb14458@xxxxxx
Quote:

>>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.
I'm surprised to find that anyone is surprised by this behaviour. If you are
logged on now, then when you started this session, that was very likely your
last (more recent) logon. If lastlogon is not updated at the end of each
logon event, when should it be updated?

/Al


My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
WinNT provider and CTP3 PowerShell
Add built-in account to local group using WinNT: ADSI provider PowerShell
how do i list winNT provider properties ? PowerShell
[VBScript](Set objUser = GetObject("WinNT://" & strComputer)) -eq [Powershell]? PowerShell
WINNT.SIF Vista installation & setup


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46