Thursday, March 12, 2015

Tracking Novell User Logins with a Batch File

I wanted to find out a way to better track which users are logging in and which systems they log onto. I was able to use a old cool solutions article that was able to help me get started in the right direction. What I wanted saved to the log file was a time stamp, computer name, Novell user name, & IP address and have that performed through a batch file that would execute when the login script runs. We will be utilizing a vbs script to run the batch file silently.

Follow these steps
  • Create the folder LNScript somewhere on your server
  • Create a Sub Folder called logs
  • Give RF rights to LNScript and RW to logs
  • Create a file named silentrunner.vbs in the LNScript folder
  • Copy this code to the file
 Set WshShell = CreateObject("WScript.Shell")  
 WshShell.run chr(34) & "F:\LNScript\track.bat" & Chr(34), 0  
 Set WshShell = Nothing  

The above code allows batch files to run silently, users will never see this batch file run. This code can be used for any other batch files you would like to run.
  • Create track.bat in the LNScript folder
  • Copy code below into track.bat
 for /f "delims=[] tokens=2" %%a in ('ping %computername% -4 -n 1 ^| findstr "["') do (set thisip=%%a)  
 echo Login Date: %Date%, Login Time: %Time%, Computer Name: %ComputerName%, User Name: %USER%, IP: %thisip%>>f:\LNScript\logs\login.csv  

This will create a csv file that has the login time & date, computer name, novell user name, & IP.

Next we need to add this code to the login script (This creates a dos variable for the novell username that we can use in the batch file)

 DOS SET USER="%1"  
 @wscript.exe F:\LNScript\silentrunner.vbs  

You can either periodically clear out the log file manually or setup a scheduled task that renames the log file. The next time someone logs in the log file will be recreated.  You don't want the log to get too big as that will cause other problems.  Below is a picture of the log file output,

Log File