|
-
Mar 6th, 2006, 02:23 AM
#1
Thread Starter
Hyperactive Member
startup and shut down time
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
DOK OCK : "The power of .net in the palm of my hand, nothing will stand in my way. Nothing." 
-
Mar 6th, 2006, 03:02 AM
#2
Lively Member
Re: startup and shut down time
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:
Code:
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run
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.
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.
Last edited by dastudios; Mar 6th, 2006 at 03:09 AM.
-
Mar 6th, 2006, 03:05 AM
#3
Lively Member
Re: startup and shut down time
This link has some useful information on getting the username:
http://support.microsoft.com/kb/q152970/
-
Mar 6th, 2006, 04:26 AM
#4
Re: startup and shut down time
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|