|
-
Oct 27th, 2000, 03:08 AM
#1
Hallo
I need to log when a user is shutting down the computer. How can I detect this to log time in a logfile?
Thank you
-
Oct 27th, 2000, 03:28 AM
#2
Fanatic Member
Hi Herman - what I'd do is make a little exe which run's on startup (either put a shortcut in the Startup folder or put it in the registry - can't remember where exactly but it's pretty easy to find) and then use your exe's form's QueryUnload event to see if windows is shutting down - then run a bit of code to append the time to a text file or something...
Code:
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
If UnloadMode = vbAppWindows Then
LogTime
End If
End Sub
I've used the above code on a little prog I made to map some network drives, and the above calls a sub that unmaps them before shutting down (I was finding my machine was hanging if I didn't unmap them) - works fine...
-
Oct 27th, 2000, 03:44 AM
#3
Hallo
Will VB pickup (in this way) when Windows95,98 or NT shuts down? I would like to detect when Windows 95,98 or NT starts shutting down. Only then must I log the time.
Thanx
-
Oct 27th, 2000, 08:02 AM
#4
Fanatic Member
Herman, yeah it will. Try it!
-
Oct 27th, 2000, 08:20 AM
#5
Guru
If Windows is shut down with the EWX_FORCE flag (for example: Ctrl+Alt+Del -> Shut Down), there is no way to log it.
Also, if your program is closed (Ctrl+Alt+Del -> your program -> End Task), it won't log it.
If you can count on the users of your program to shut down the computer normally and to not close your program, coox's method works. 
To make it a tiny bit harder to close your program (it will always be possible to close it somehow):
Code:
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
Dim btFile As Byte
If UnloadMode = vbAppWindows Then
' Windows is closing... Log it:
btFile = FreeFile
Open "C:\ShutDown.log" For Append As btFile
Print #btFile, "Shutdown at: " & Now
Close btFile
Else
' Your app is closing... Try to prevent it:
Cancel = True
End If
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
|