Skip Navigation Links.
Logs Bootups and Log-Ons on your computer.
Language(s):Visual Basic 6.0
Category(s):Internet Explorer

This is about as simple as a VB Program gets. Compile this project, and place a shortcut to the executable in the Windows Startup Folder. For each log on to Windows, an entry is written to a text file, containing date, time and user. A record is written even if the user ESCapes out. Not a security measure, just a tattle-tale.

' 1) Start VB and Create a new project. Form1 will be created by default.
' 2) No controls need to be added.  The log file name and path can be specified
'    by changing the Constant "myPath" in the Form Load Sub.
' 3) Paste the following code into the declarations section of Form1:

'      --- Begin code for Form1
'GSSLogOn: Creates a logfile of all bootups and logons to the device. A text file
'          called GSSLogOn.log will be created in the path that the application is
'          running it.
'          If you're the only user of your computer, it's still  a useful tool.
'          You can review the log to remind you of how often you have to reboot Windows*.
'             * Windows is a trademark of the Microsoft Corporation.
'Author: George Pearson
'Created 9/01/2002

Option Explicit

' API to retrieve Log On Profile name
Private Declare Function GetUserName _
    Lib "advapi32.dll" Alias "GetUserNameA" _
      (ByVal lpBuffer As String, nSize As Long) _
         As Long 'username only

Public Function GetUser()
Dim UserName As String
Dim lpBuff As String * 25
Dim ret As Long ', username As String
ret = GetUserName(lpBuff, 25)
GetUser = Left(lpBuff, InStr(lpBuff, Chr(0)) - 1)
UserName = GetUser

' Trap if User Escaped out of the log on.
If Len(UserName) = 0 Then UserName = "Null"
End Function

Private Sub Form_Load()

Const strLogFile = "GSSLogOn.log"
Dim FileNumber As Integer
Dim strMyPath As String
Dim strInfo As String
strMyPath = App.Path
If Right$(strMyPath, 1) <> "\" Then
  strMyPath = strMyPath & "\"
End If
strMyPath = strMyPath & strLogFile

FileNumber = FreeFile
Open strMyPath For Append As #FileNumber
strInfo = ("Booted " & Format(Now, "ddddd ttttt") & " by User: " & GetUser)
Print #FileNumber, strInfo
Close #FileNumber
End Sub

This article has been viewed 1693 times.
The examples on this page are presented "as is". They may be used in code as long as credit is given to the original author. Contents of this page may not be reproduced or published in any other manner what so ever without written permission from Idioma Software Inc.