Visual Basic Code Samples - GSSLogOn - Captures LogOn information for your PC Author: George Pearson Company: Green Springs Software, Inc. www.green-springs.com Purpose: Programmers Utility to list discrete entries from a database file. Uses ASC's Sequel Product Components: Project1 Visual Basic 5 or 5 Project Written: 9/2002 This is a simple program that you can simply copy into a Visual Basic Standard EXE Project, Compile, and have a working program. The program uses a Windows API (GetUserName) to capture the Log on User ID, and writes that and the date and time to a log file (GSSLogOn.log) in the Folder that the project is running in. You can change the desired path and Log file name in the Form Load Sub. Instructions: 1) Start a New VB Standard Exe Project. Form1 will be created by default. 2) Paste the following code into the Declarations section of form1. 3) No controls need to be added. 4) Save, Compile and run. Check your Log File. 5) To use, copy a shortcut to the executeable into the Windows Startup folder. Each time the computer is booted up, or Logged on, a record is written to the log file. ~ Enjoy: ' --- 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. ' 'Author: George Pearson george@green-springs.com ' 'Created 9/01/2002 ' 'www.green-springs.com 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 End Sub ' ******** End Of Source (GSSLogOn) Visual Basic Program *************