Page 1 of 2 12>
Topic Options
#146155 - 2005-08-22 06:48 PM Help with script to track logoff times
hywaydave Offline
Fresh Scripter

Registered: 2005-07-20
Posts: 26
I would like to track when users log off their workstations. I have created this script but it doesn't seem to be working. Do I first need a command to create the log file if it doesn't exist? I tried creating a log file manaully and that didn't work either.

$logfile = "\\servername\userlogs$\@USERID.log"
$logfile = WRITELINE("LOGOFF ;"+@DATE+";"+@TIME+";"+@USERID+";"+@WKSTA+@CRLF)

Top
#146156 - 2005-08-22 07:46 PM Re: Help with script to track logoff times
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Open() will do it for you provided you use the right parms.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#146157 - 2005-08-22 08:04 PM Re: Help with script to track logoff times
hywaydave Offline
Fresh Scripter

Registered: 2005-07-20
Posts: 26
I don't get what that filehandle parameter is for. Kixtart command reference doesn't explain it. Would I do something like this then?

$logfile = "\\servername\@USERID.log"
Open(1, $logfile, 1)
$logfile = WRITELINE("LOGOFF ;"+@DATE+";"+@TIME+";"+@USERID+";"+@WKSTA+@CRLF)

And would I also need a .bat file that calls the kixtart script like this:

kix32.exe logoff.kix


Edited by hywaydave (2005-08-22 08:04 PM)

Top
#146158 - 2005-08-22 08:07 PM Re: Help with script to track logoff times
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Each Open() file requires a unique file handle.

If you want to open a file for write access, and create it if it does not yet exist, you should specify 5.

$RC = Open(1, $logfile, 5)
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#146159 - 2005-08-22 08:12 PM Re: Help with script to track logoff times
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
You're missing the file handle on the WriteLine().
$RC = WriteLine(1,"LOGOFF ;"+@DATE+";"+@TIME+";"+@USERID+";"+@WKSTA+@CRLF)
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#146160 - 2005-08-22 08:14 PM Re: Help with script to track logoff times
hywaydave Offline
Fresh Scripter

Registered: 2005-07-20
Posts: 26
could you please be a little more clearer? What am I suppose to do with $RC? This script is not working and the permissions on that folder are correct. I even tried this:

$logfile = Open(1, "\\servername\userlogs$\@USERID.log", 1)
$logfile = WRITELINE("LOGOFF ;"+@DATE+";"+@TIME+";"+@USERID+";"+@WKSTA+@CRLF)

According to Kixtart, the mode should be a 1 instead of a 5.
1 If the file does not exist, Open( ) will create a new file.

Top
#146161 - 2005-08-22 08:18 PM Re: Help with script to track logoff times
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
$RC as often shown in the manual, is the return code. You check the return code if you are not optimistic.

Quote:


According to Kixtart, the mode should be a 1 instead of a 5.
1 If the file does not exist, Open( ) will create a new file.



If you want to argue, I'll just leave.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#146162 - 2005-08-22 08:33 PM Re: Help with script to track logoff times
hywaydave Offline
Fresh Scripter

Registered: 2005-07-20
Posts: 26
I'm not arguing, I just want to make sure I'm on the right track. I appreciate your help a lot. I'll try using the 5 for my mode.
Top
#146163 - 2005-08-22 08:48 PM Re: Help with script to track logoff times
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
OK, and put the file handle in the WriteLine() like I told you.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#146164 - 2005-08-22 09:01 PM Re: Help with script to track logoff times
hywaydave Offline
Fresh Scripter

Registered: 2005-07-20
Posts: 26
Thanks.

My next question. I want this to run when the user logs off. So I created a GPO and in the logoff script properties I specified the logoff.bat file, which will be located in:
\\domainname.com\SysVol\domainname.com\Policies\{AD4DEG97-AS8C-4470-B8C8-2E13B477245V}\User\Scripts\Logoff

I have the kix32.exe and my logoff.kix script (which we worked on above) in this directory too. The logoff.bat file reads:

kix32.exe logoff.kix

I receive this error when it's ran.
ERROR: failed to find/open script [logoff.kix]!

Top
#146165 - 2005-08-22 09:21 PM Re: Help with script to track logoff times
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
See the FAQ GPO Change-over where it was suggested to use the full UNC paths.

\\domain.tld\netlogon\WKiX32.exe \\domain.tld\netlogon\script.KiX
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#146166 - 2005-08-22 09:53 PM Re: Help with script to track logoff times
hywaydave Offline
Fresh Scripter

Registered: 2005-07-20
Posts: 26
.
Top
#146167 - 2005-08-22 10:02 PM Re: Help with script to track logoff times
hywaydave Offline
Fresh Scripter

Registered: 2005-07-20
Posts: 26
OK, maybe it's not working yet. I can run the logoff.bat file from command line and it'll create or update the log file, but when I logoff Windows will say "running logoff scripts" but it doesn't create the file.
Top
#146168 - 2005-08-22 10:35 PM Re: Help with script to track logoff times
hywaydave Offline
Fresh Scripter

Registered: 2005-07-20
Posts: 26
Will the @USERID work in a logoff script?
Top
#146169 - 2005-08-22 10:38 PM Re: Help with script to track logoff times
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
If not then %username% will work because this script runs before the user is really logged of afaik.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#146170 - 2005-08-22 10:44 PM Re: Help with script to track logoff times
hywaydave Offline
Fresh Scripter

Registered: 2005-07-20
Posts: 26
I even took out the @userid part and just tried to have the logoff script create a test.txt file and it never did. Although when I logoff, Windows says "running logoff scripts".
Top
#146171 - 2005-08-22 10:47 PM Re: Help with script to track logoff times
hywaydave Offline
Fresh Scripter

Registered: 2005-07-20
Posts: 26
Tried using %username% and had the same results.
Top
#146172 - 2005-08-23 04:44 AM Re: Help with script to track logoff times
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Why does everybody want to make it so complicated? Enable logon/logoff auditing on the domain controllers and/or local computers and just pull the relevant information from the eventlog via e.g. ReadEventlog() - Retrieves event from the eventlog

Code:

$events = ReadEventlog('SELECT TimeGenerated, User
FROM Win32_NTLogEvent
WHERE Logfile="Security" AND EventCode=538
AND TimeGenerated>="20050801000000.000000-240"')


pulls all logoff events from the local computer after 2005-08-01 midnight using a 240 minute time offset from GMT.

See also Tracking Logon and Logoff Activity in Windows 2000
_________________________
There are two types of vessels, submarines and targets.

Top
#146173 - 2005-08-23 02:53 PM Re: Help with script to track logoff times
hywaydave Offline
Fresh Scripter

Registered: 2005-07-20
Posts: 26
This is for Human Resources to look at and they want to be able to look at a log at any given time for any given employee without me having to run a script with a specific date. So does anyone have an idea as to why this logoff script won't work from the logoff GPO but it'll work just fine when I just run the batch file from command line?
Top
#146174 - 2005-08-23 03:31 PM Re: Help with script to track logoff times
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
Just a quick plug...

You can use fnDateTime() to get a properly formatted date string localized for your timezone.

Code:

fnDateTime("1-Aug-2005",3)


Top
Page 1 of 2 12>


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 1183 anonymous users online.
Newest Members
batdk82, StuTheCoder, M_Moore, BeeEm, min_seow
17885 Registered Users

Generated in 0.078 seconds in which 0.03 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org