Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Prevent user from restarting computer during background process

Status
Not open for further replies.

codefinger

Programmer
Feb 2, 2002
14
US
VB 6.0 on W2000 computer:

I want to at least warn the user that a background process is not complete before allowing them to log off or restart the computer.

I have researched enough to come up with the following code:

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)

If UnloadMode = 1 Then

Exit Sub
Else

If MsgBox("Warning! Scans are being uploaded." + vbCrLf + _
"Logging off the computer will abort the upload." + vbCrLf +
vbCrLf + _
"Quit anyway?", vbOKCancel, App.ProductName) = vbOK Then
Exit Sub

Else

Cancel = True

End If

End If

End Sub


This comes close to doing what I want, but it is very messy. For one thing, a message box appears that just says "Cannot quit." I did not code that message, so it must be coming from the system. Also, the End Program dialog box comes up and blots out both the "Cannot quit" message box and my carefully worded text.

Does someone have a cleaner way for me to accomplish my objective, or a way to avoid these problems?

(The user is most likely to log off by clicking start/restart or start/logoff)

Thanks in advance for any kind assistance you can offer.
 
As a simple example you could use the form unload event and set a boolean variable to state when the user can quit.

i.e.

Code:
Dim blnQuit As Boolean

Private Sub Command1_Click()
blnQuit = True
End Sub

Private Sub Form_Unload(Cancel As Integer)
If blnQuit = False Then 
msgbox "Not Allowed"
Cancel = True
end if
End Sub


If you try to quit the form it will not allow you to do so unless you have clicked the command button first.

Another alternative may be to capture the log off/shutdown command and abort it until your process has finished (like if you have Microsoft Office open and you try to shutdown you get a message telling you to quit all Microsoft applications first). This may however be annoying to the user but that is up to you how you wish to do it.
 
>>Another alternative may be to capture the log off/shutdown command and abort it until your process has finished (like if you have Microsoft Office open and you try to shutdown you get a message telling you to quit all Microsoft applications first). <<


Can you provide an example of how this is done?

Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top