Announcement

Collapse

Forum Guidelines

This forum is for finished source code that is working properly. If you have questions about this or any other source code, please post it in one of the Discussion Forums, not here.
See more
See less

Logon recorder and viewer

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Mike Doty
    replied
    Updated for current compiler
    Code:
    #COMPILE EXE
    #DIM ALL
    #INCLUDE "WIN32API.INC"
    DECLARE SUB LogonOff(Action&,MachineNumber$,MachineName$)
    DECLARE FUNCTION ComputerName AS STRING
    %RefreshTime = 1000
    %RecLen = 128  'minimum = 65   63 bytes unused per record
    %MAX_COMPUTERNAME_LENGTH = 15    'not in Win32Api.inc
    '
    SUB HELP
    PRINT "LogOnOff.Bas     6/1/2000   Compiled USING PB/CC 2.0
    PRINT "                 Comments/suggestions  mailto:[email protected]@home.com</A>
    PRINT "Some uses:
    PRINT " 1 See who/when users log in and out of your program
    PRINT " 2 Creates a unique terminal number for each terminal
    PRINT " 3 Count number of terminals logged into your program
    PRINT " 4 Modify to pass information between terminals by record number
    PRINT " 5 Increment a logon counter to create an instance counter for your
    PRINT "   program to create unique output files for the program.
    PRINT "Action = 1
    PRINT "   A file named 'machines' is searched for the computer name.
    PRINT "   If found, the record number it was found in and the computer
    PRINT "   name are returned.  This routine returns computer names for
    PRINT "   you using the GetComputerName API.  Do not pass a name.
    PRINT "   New computer names found are added as 128-byte records.
    PRINT "Syntax:
    PRINT "   CALL LogOnOff(Action&,MachineNumber$,MachineName$)
    PRINT "     Action = 0  log user off at end of your program
    PRINT "     Action = 1  log user on at beginning of your program
    PRINT "     Action = 2  view log in real-time
    PRINT "     MachineNumber$ and MachineName$ are returned (nothing passed)
    PRINT
    PRINT "     To see users logged in,  [press any key]  Action = 2
    WAITKEY$
    END SUB
    '
    TYPE LogType    '128 byte records  63 bytes unused
      MachineNumberOnDisk AS STRING * 6
      MachineNameOnDisk AS STRING * 17
      STATUS AS STRING * 10
      LogIn AS STRING * 16
      LogOut AS STRING * 16
      Dummy AS STRING * 63
    END TYPE
    '
    TYPE LogTypeAll
       Buffer AS STRING * 128
    END TYPE
    '
    FUNCTION PBMAIN AS LONG
       COLOR 7,1,1
       CLS
       CALL HELP
        DIM action AS LONG
       DIM MachineNumber AS STRING
       DIM Machinename AS STRING
        Action = 1  'Call this at the beginning of your program
       CALL LogOnOff(Action,MachineNumber,MachineName)
        Action = 2  'Call this to see who is logged on
       CALL LogOnOff(Action,MachineNumber,MachineName)
        Action = 0  'Call this when a user ends program
       CALL LogOnOff(Action,MachineNumber,MachineName)
    END FUNCTION
    '
    '
    SUB LogOnOff (Action AS LONG, MachineNumber AS STRING, _
                  Machinename AS STRING)
       ON ERROR GOTO LogOnError
        DIM Org AS STRING
       DIM DataBaseDir AS STRING
       DIM FileNum AS LONG
       DIM Record AS LONG
       DIM FilName AS STRING
       DIM xx AS STRING
       DIM MachineNum AS LONG
        DIM User AS LogType
       DIM Everything AS LogTypeAll
     
    SELECT CASE Action
       CASE 0 TO 1   '0=log out  1=log in
          Machinename$ = ComputerName  'calls ComputerName$ function
          IF LEN(Machinename$) = 0 THEN EXIT SUB
       CASE 2
          GOTO DisplayLog
       CASE ELSE
          EXIT SUB
    END SELECT
       org$ = DataBaseDir$ + "MACHINES"
       filenum = FREEFILE
       OPEN org$ FOR RANDOM SHARED AS #filenum LEN = %RecLen
        FOR Record = 1 TO LOF(filenum) / %RecLen
          GET #filenum, Record,User
          IF INSTR(User.MachineNameOnDisk, Machinename$) THEN
             MachineNum = Record  'found machine in log
             EXIT FOR
          END IF
       NEXT
       IF MachineNum = 0 THEN
          MachineNum = LOF(filenum) \ %RecLen + 1
           'init the buffer TO ALL spaces
          User.MachineNumberOnDisk = ""
          User.MachineNameOnDisk = ""
          User.Status = ""
          User.LogIn = ""
          User.LogOut = ""
       END IF
        MachineNumber$ = LTRIM$(STR$(MachineNum))
       User.MachineNumberOnDisk$ = MachineNumber$
       User.MachineNameOnDisk$ = Machinename$
        org$ = LEFT$(TIME$, 5) + " " + LEFT$(DATE$, 5)
       IF Action = 0 THEN
          User.LogOut = org$
          User.Status$ = "-"
       ELSEIF Action = 1 THEN
          User.LogIn = org$
          User.Status = "ACTIVE"
       END IF
       PUT #filenum, MachineNum,User
       CLOSE #filenum
    EXIT SUB
    '
    DisplayLog:   'Action = 2
       filenum = FREEFILE
       FILNAME$ = DataBaseDir$ + "Machines"
       OPEN FILNAME$ FOR RANDOM SHARED AS #filenum LEN = %RecLen
       CLS
       PRINT TAB(33); "USER ACTIVITY"; TAB(58); "Press any key to exit"
       LOCATE 3, 1
       PRINT "NODE  MACHINE NAME"; TAB(24); "STATUS    LAST LOGIN"; TAB(50); _
        "LAST LOGOUT"
    DO
       LOCATE 1, 1: PRINT TIME$
       LOCATE 5, 1
        FOR Record = 1 TO LOF(filenum) / %RecLen
          GET #filenum, Record,Everything
          PRINT LEFT$(Everything.BUFFER, 80)
       NEXT
       SLEEP %RefreshTime '1000 = 1 second
       xx$ = INKEY$ '5/29/99
       IF LEN(xx$) THEN EXIT DO
    LOOP
       CLOSE #filenum
       EXIT SUB
    LogOnError:
       CLS
       PRINT "Unable to UPDATE terminal id file named MACHINES."
       PRINT "Please check that the drive is not READONLY."
       PRINT "Ending program"
       PRINT "Press any key"
       WAITKEY$
       RESUME 100
    100
    END SUB
    '
    FUNCTION ComputerName AS STRING
      DIM RetCode AS LONG
      DIM lpBuffer AS  ASCIIZ * %MAX_COMPUTERNAME_LENGTH + 1
      DIM nSize AS LONG
      nSize = %MAX_COMPUTERNAME_LENGTH + 1
      RetCode = GetComputerName(lpBuffer,nSize) 'nSize returns length
      FUNCTION = lpBuffer
    END FUNCTION

    Leave a comment:


  • Mike Doty
    started a topic Logon recorder and viewer

    Logon recorder and viewer

    Code:
    #REGISTER NONE
    #COMPILE EXE
    #DIM ALL
    #INCLUDE "WIN32API.INC"
    DECLARE SUB LogonOff(Action&,MachineNumber$,MachineName$)
    DECLARE FUNCTION ComputerName AS STRING
    '
    SUB Help
    PRINT "LogOnOff.Bas     6/1/2000   Compiled USING PB/CC 2.0
    PRINT "                 Comments/suggestions  [url="mailto:[email protected]"]mailto:[email protected][/url][email protected]</A> 
    PRINT "Some uses:
    PRINT " 1 See who/when users log in and out of your program
    PRINT " 2 Creates a unique terminal number for each terminal
    PRINT " 3 Count number of terminals logged into your program
    PRINT " 4 Modify to pass information between terminals by record number
    PRINT " 5 Increment a logon counter to create an instance counter for your
    PRINT "   program to create unique output files for the program.
    PRINT "Action = 1
    PRINT "   A file named 'machines' is searched for the computer name.
    PRINT "   If found, the record number it was found in and the computer
    PRINT "   name are returned.  This routine returns computer names for
    PRINT "   you using the GetComputerName API.  Do not pass a name.
    PRINT "   New computer names found are added as 128-byte records.
    PRINT "Syntax:
    PRINT "   CALL LogOnOff(Action&,MachineNumber$,MachineName$)
    PRINT "     Action = 0  log user off at end of your program
    PRINT "     Action = 1  log user on at beginning of your program
    PRINT "     Action = 2  view log in real-time
    PRINT "     MachineNumber$ and MachineName$ are returned (nothing passed)
    PRINT
    PRINT "     To see users logged in,  [press any key]  Action = 2
    WAITKEY$
    END SUB
    '
    Type LogType    '128 byte records  63 bytes unused
      MachineNumberOnDisk AS STRING * 6
      MachineNameOnDisk AS STRING * 17
      STATUS AS STRING * 10
      LogIn AS STRING * 16
      LogOut AS STRING * 16
      Dummy AS STRING * 63
    END type
    '
    Type LogTypeAll
       Buffer AS STRING * 128
    END type
    '
    FUNCTION PBMAIN AS LONG
       COLOR 7,1,1
       CLS
       CALL Help
    
       DIM action AS LONG
       DIM MachineNumber AS STRING
       DIM Machinename AS STRING
    
       Action = 1  'Call this at the beginning of your program
       CALL LogOnOff(Action,MachineNumber,MachineName)
    
       Action = 2  'Call this to see who is logged on
       CALL LogOnOff(Action,MachineNumber,MachineName)
    
       Action = 0  'Call this when a user ends program
       CALL LogOnOff(Action,MachineNumber,MachineName)
    END FUNCTION
    '
    '
    SUB LogOnOff (Action AS LONG, MachineNumber AS STRING, _
                  Machinename AS STRING)
       ON ERROR GOTO LogOnError
    
       DIM Org AS STRING
       DIM DataBaseDir AS STRING
       DIM FileNum AS LONG
       DIM Record AS LONG
       DIM FilName AS STRING
       DIM xx AS STRING
       DIM MachineNum AS LONG
    
       DIM User AS LogType
       DIM Everything AS LogTypeAll
       %RefreshTime = 1000
    
       %RecLen = 128  'minimum = 65   63 bytes unused per record
    
    SELECT CASE Action
       CASE 0 TO 1   '0=log out  1=log in
          Machinename$ = ComputerName  'calls ComputerName$ function
          IF LEN(Machinename$) = 0 THEN EXIT SUB
       CASE 2
          GOTO DisplayLog
       CASE ELSE
          EXIT SUB
    END SELECT
       org$ = DataBaseDir$ + "MACHINES"
       filenum = FREEFILE
       OPEN org$ FOR RANDOM SHARED AS #filenum LEN = %RecLen
    
       FOR Record = 1 TO LOF(filenum) / %RecLen
          GET #filenum, Record,User
          IF INSTR(User.MachineNameOnDisk, Machinename$) THEN
             MachineNum = Record  'found machine in log
             EXIT FOR
          END IF
       NEXT
       IF MachineNum = 0 THEN
          MachineNum = LOF(filenum) \ %RecLen + 1
    
          'init the buffer TO ALL spaces
          User.MachineNumberOnDisk = ""
          User.MachineNameOnDisk = ""
          User.Status = ""
          User.LogIn = ""
          User.LogOut = ""
       END IF
    
       MachineNumber$ = LTRIM$(STR$(MachineNum))
       User.MachineNumberOnDisk$ = MachineNumber$
       User.MachineNameOnDisk$ = Machinename$
    
       org$ = LEFT$(TIME$, 5) + " " + LEFT$(DATE$, 5)
       IF Action = 0 THEN
          User.LogOut = org$
          User.Status$ = "-"
       ELSEIF Action = 1 THEN
          User.LogIn = org$
          User.Status = "ACTIVE"
       END IF
       PUT #filenum, MachineNum,User
       CLOSE #filenum
    EXIT SUB
    '
    DisplayLog:   'Action = 2
       filenum = FREEFILE
       FILNAME$ = DataBaseDir$ + "Machines"
       OPEN FILNAME$ FOR RANDOM SHARED AS #filenum LEN = %RecLen
       CLS
       PRINT TAB(33); "USER ACTIVITY"; TAB(58); "Press any key to exit"
       LOCATE 3, 1
       PRINT "NODE  MACHINE NAME"; TAB(24); "STATUS    LAST LOGIN"; TAB(50); _
        "LAST LOGOUT"
    DO
       LOCATE 1, 1: PRINT TIME$
       LOCATE 5, 1
    
       FOR Record = 1 TO LOF(filenum) / %RecLen
          GET #filenum, Record,Everything
          PRINT LEFT$(Everything.BUFFER, 80)
       NEXT
       SLEEP %RefreshTime '1000 = 1 second
       xx$ = INKEY$ '5/29/99
       IF LEN(xx$) THEN EXIT DO
    LOOP
       CLOSE #filenum
       EXIT SUB
    LogOnError:
       CLS
       PRINT "Unable to UPDATE terminal id file named MACHINES."
       PRINT "Please check that the drive is not READONLY."
       PRINT "Ending program"
       PRINT "Press any key"
       WAITKEY$
       RESUME 100
    100
    END SUB
    '
    FUNCTION ComputerName AS STRING
      %MAX_COMPUTERNAME_LENGTH = 15    'not in Win32Api.inc
      DIM RetCode AS LONG
      DIM lpBuffer AS  ASCIIZ * %MAX_COMPUTERNAME_LENGTH + 1
      DIM nSize AS LONG
      nSize = %MAX_COMPUTERNAME_LENGTH + 1
      RetCode = GetComputerName(lpBuffer,nSize) 'nSize returns length
      FUNCTION = lpBuffer
    END FUNCTION
Working...
X