Hi guyz,
How can I know the startup and shutdown time and write them to a file?
I also want to know the currently logged username.
Thanks
Printable View
Hi guyz,
How can I know the startup and shutdown time and write them to a file?
I also want to know the currently logged username.
Thanks
Create a program that logs the time when it is run, and the time it is closed to a file. (One that uses a module only and has no form)
To get the current username that is logged on there is an API - GetUserName I think - use the API viewer that comes with VB to find it.
Then, you can either write code to do this or do it manually: create a string registry key in:
Give it any name you want and make the value point to the path of your exe file. It would be good to put your exe in the windows directory to avoid someone accidentally deleting it.Code:HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run
OR
You could register it as a service process, that starts up before the user logs on - the only downside is you will have to run it as a separate user - making it very difficult to get who else is logged on.
This link has some useful information on getting the username:
http://support.microsoft.com/kb/q152970/
Something like this.
VB Code:
Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long Private Sub Form_Load() WriteToFile "Startup" End Sub Sub WriteToFile(State As String) Dim FF As Integer Dim StrUserName As String FF = FreeFile() Open "D:\LogDetails.txt" For Append As #FF Print #FF, "UserName: " & StrUserName & vbCrLf & _ "State: " & State & vbCrLf & _ "Time: " & Now & vbCrLf & String(20, "-") Close #FF End Sub Private Sub Form_Unload(Cancel As Integer) WriteToFile "ShutDown" End Sub