' 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 firstname.lastname@example.org
' 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"
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 & "\"
strMyPath = strMyPath & strLogFile
FileNumber = FreeFile
Open strMyPath For Append As #FileNumber
strInfo = ("Booted " & Format(Now, "ddddd ttttt") & " by User: " & GetUser)
Print #FileNumber, strInfo