WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Network

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Logging NT login

Keywords: Logging NT login 

This is a way to track who is logging into our NT workstations, both at the local level (each WS) and on the network level to centralize who is logging in where, and when.

The WinBatch program below 'LOGINLOG' I wrote that does just that. It creates a tab-delimited list to %WINDIR%\LOGIN.LOG to track local logins:

 Date / Time / Computer / UserName 
and notes whether the WS is in ** STANDALONE ** mode.

And it creates a network-centric tab-delimited log file to track NT workstations logging into a Novell Network:

Date / Time / Computer / UserName / LoginName / Network Address / MAC Address

Feel free to share with others. However, this is only tested on NT workstations logging into a Novell 4.x network.

;****************************************************************************************
; LOGINLOG.EXE INFO									*
; SYNTAX:  LOGINLOG (ADD / REMOVE) (QUIET)						*
;											*
; ADD - Will add LOGINLOG.EXE to the HKLM Run line to automatically run upon login.	*
; REMOVE - Will remove LOGINLOG.EXE from the HKLM Run line, disabling the logging	*
; QUIET - Will add/remove LOGINLOG without confirmation (quiet mode)			*
;****************************************************************************************

By running LOGINLOG.EXE while holding down the CTRL key, you will have the options to view either the LOCAL log file or the NETWORK log file, and configure a specified path to keep the network-based log file. By default, the LOG file (and the configuration INI file) will be located in the same directory as LOGINLOG.EXE is executed from.

Enjoy.

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;LOGINLOG.WBT  Definition of program
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Initialize variable used within program
        CR=strcat(num2char(13),num2char(10))            ;Carriage Return
        tabchr=Num2Char(9)                              ;Tab
        WinDir=Environment("windir")                    ;Get Windows working directory
        InitialWindow=WinGetActive()                    ;Gets current Active window
        ExeName=WinName()
        WinHide("%ExeName%")
        ExeName=StrUpper(StrSub(ExeName,7,-1))
	     Vdot=FileVerInfo(ExeName, "", "FileVersion")
        ExeRoot=StrUpper(FileRoot(ExeName))
        Path2Exe=FileLocate("%ExeName%")         ;Go find where default.wbt lives
        Path2Exe=StrUpper(FilePath(Path2Exe))
        if IsKeyDown(@CTRL)==@YES then goto CONTROL

:BEGIN
	ErrorMode(@OFF)
	if param0=="1" then goto AUTORUN
	ComputerName=Environment("COMPUTERNAME")
	ComputerName=StrFix(ComputerName," ",17)
	UserName=Environment("USERNAME")
	UserName=StrFix(Username," ",17)
	NOW=TimeYmdHms()
	Year=ItemExtract(1,NOW,":")
	Month=ItemExtract(2,NOW,":")
	Day=ItemExtract(3,NOW,":")
	Hours=ItemExtract(4,NOW,":")
	Minutes=ItemExtract(5,NOW,":")
	Seconds=ItemExtract(6,NOW,":")

	Date=StrCat(Month,"-",Day,"-",Year)
	Time=StrCat(Hours,":",Minutes,":",Seconds)

:STARTDEBUG
	NWUserName=Environment("NWUSERNAME")
	if NWUserName==""
		Other="** STANDALONE **"
	Else
		DEPT=Environment("DEPT")
		Other="%NWUSERNAME% / %DEPT%"
	EndIf


:LOCALLOG
	LocalLogRecord=StrCat(Date,@TAB,Time,@TAB,ComputerName,@TAB,UserName)
	WinDir=Environment("windir")
	LoginLog="%WinDir%\LOGIN.LOG"
	LocalLoginLog=LoginLog
	if FileExist(LoginLog)==@FALSE
		gosub LOCALLOGHEADER
		handle = FileOpen(LoginLog,"WRITE")
		filewrite(handle,Header)
		filewrite(handle,Divider)
		fileclose(handle)
	Else
	EndIf
	handle = FileOpen(LoginLog,"APPEND")
	FileWrite(handle,"%LocalLogRecord%%tabchr%%Other%")
	FileClose(handle)
	if NWUserName=="" then Exit

:NETWORKLOG
	AddExtender("wwn4x34I.dll")
	LoginLog=FileLocate("%ExeRoot%.LOG")
;	LoginLog="X:\LOGS\NTLOGINS.LOG"
	NetworkLoginLog=LoginLog
	LoginLogINI=FileLocate("%ExeRoot%.INI")
	if LoginLogINI<>"" then gosub READINI
	if FileExist(LoginLog)==@FALSE 
		gosub NETWORKLOGHEADER
		handle = FileOpen(LoginLog,"WRITE")
		filewrite(handle,Header)
		filewrite(handle,Divider)
		fileclose(handle)
	Else
	EndIf

;MAC Address
	TempNetAddr = n4GetNetAddr("",0)
	NWUserName=Environment("NWUSERNAME")
	NWUserName=StrFix(NWuserName," ",10)
	Network=ItemExtract(1,TempNetAddr,":")
	MAC=ItemExtract(2,TempNetAddr,":")
	VOPSTDVER=Environment("VOPSTDVER")
	NetworkLogRecord=StrCat(LocalLogRecord,@TAB,NWUserName,@TAB,Network,@TAB,MAC,@TAB,VOPSTDVER)
	handle = FileOpen(LoginLog,"APPEND")
	FileWrite(handle,NetworkLogRecord)
	FileClose(handle)
	Exit

:LOCALLOGHEADER
	Header=StrCat("Date       ",@TAB,"Time     ",@TAB,"Computer         ",@TAB,"UserName         ",@TAB)
	Divider=StrCat("===========",@TAB,"=========",@TAB,"=================",@TAB,"=================",@TAB)
	Return

:NETWORKLOGHEADER
	gosub LOCALLOGHEADER
	Header=StrCat(Header,"LoginName",@TAB,"Network ",@TAB,"MAC         ",@TAB,"v. NTSL")
	Divider=StrCat(Divider,"==========",@TAB,"=========",@TAB,"=============",@TAB,"========")
	Return

:READINI
	LoginLog=IniReadPvt("Settings","LogFile","Z:\PUBLIC\NTLOGIN.LOG",LoginLogINI)
	Return

:AUTORUN
	LMRun=RegOpenKey(@REGMACHINE,"SOFTWARE\Microsoft\Windows\CurrentVersion\Run")
	if StrUpper(param1)=="REMOVE" || StrUpper(param1)=="DELETE"
		RegDelValue(LMRun,"[LoginLog]")
		if param0=="2" then Exit
		Message(StrUpper(param1),"LOGINLOG.EXE disabled")
	Else
		RegSetValue(LMRun,"[LoginLog]","LOGINLOG.EXE")
		Source=FileLocate("%ExeName%")
		Destination=Environment("windir")
		FileCopy(source,destination,@FALSE)
		if param0=="2" then Exit
		Message("Installed","LOGINLOG.EXE add to run automatically upon login")
		EndIf
	RegCloseKey(LMRun)
	Exit

:CONTROL
	ControlFormat=`WWWDLGED,5.0`
	
	ControlCaption=`LOGIN LOG MANAGER v.%vdot%`
	ControlX=59
	ControlY=55
	ControlWidth=95
	ControlHeight=86
	ControlNumControls=5
	
	Control01=`10,66,36,DEFAULT,PUSHBUTTON,DEFAULT,"&OK",1`
	Control02=`48,66,36,DEFAULT,PUSHBUTTON,DEFAULT,"&Cancel",0`
	Control03=`16,8,64,DEFAULT,PUSHBUTTON,DEFAULT,"&Local Log",2`
	Control04=`16,24,64,DEFAULT,PUSHBUTTON,DEFAULT,"&Network Log",3`
	Control05=`16,40,64,DEFAULT,PUSHBUTTON,DEFAULT,"LOGINLOG.&INI",4`
	
	ButtonPushed=Dialog("Control")
	if ButtonPushed=="2" then goto OPENLOCALLOG
	if ButtonPushed=="3" then goto OPENNETWORKLOG
	if ButtonPushed=="4" then goto OPENLOGINLOGINI
	if IsKeyDown(@CTRL)==@YES 
		Debug(@ON)
		goto STARTDEBUG
	Else
	EndIf
	Exit

:OPENLOCALLOG
	WinDir=Environment("windir")
	LoginLog="%WinDir%\LOGIN.LOG"
	RunWait("NOTEPAD.EXE",LOGINLOG)
	goto CONTROL

:OPENNETWORKLOG
	gosub CHKNETWORK
	LoginLog="X:\LOGS\NTLOGINS.LOG"
	NetworkLoginLog=LoginLog
	LoginLogINI=FileLocate("%ExeRoot%.INI")
	if LoginLogINI<>"" then gosub READINI
	RunWait("NOTEPAD.EXE",LOGINLOG)
	goto CONTROL

:OPENLOGINLOGINI
	gosub CHKNETWORK
	LoginLogINI=FileLocate("%ExeRoot%.INI")
	if LoginLogINI=="" 
		LoginLogINI="%Path2Exe%\%ExeRoot%.INI"
		IniWritePvt("Settings","LogFile","Z:\PUBLIC\NTLOGIN.LOG",LoginLogINI)
		gosub READINI
	Else
		gosub READINI
	EndIf
	Message("","Opening %LoginLogINI%")
	RunWait("NOTEPAD.EXE",LOGINLOGINI)
	goto CONTROL

:NONETWORK
	Message("No Network","Network is not available")
	goto CONTROL

:CHKNETWORK
	if Environment("NWUSERNAME")=="" then goto NONETWORK
	Return


Article ID:   W14294
Filename:   Logging NT login.txt
File Created: 2001:03:01:12:45:32
Last Updated: 2001:03:01:12:45:32