Solved

Prevent a forced quit

Posted on 2000-02-20
7
191 Views
Last Modified: 2010-05-02
Hi all,

How can I prevent a forced quit of my program by the user pressing CTRL-ALT-DEL and Ending the task?

I have added code to prevent the close box working, is there a way to stop the program name appearing in the task list?

thanks!!
0
Comment
Question by:georgep23
7 Comments
 
LVL 1

Expert Comment

by:mmips
ID: 2539911
Try setting the form property showintaskbar = false (at the design time form properties window...

This does not allow the window to show in the task bar and MAY not show up in the task list...I haven't tried that...
0
 
LVL 1

Expert Comment

by:mmips
ID: 2539931
The following is from VB 3.0 you could try and see if it will work for your app...

How to Hide a VB App from the Task List and ALT+TAB Order

Article ID: Q114776

The information in this article applies to:
- Standard and Professional Editions of Microsoft Visual Basic for

  Windows, versions 2.0 and 3.0



SUMMARY
This article demonstrates how to create an application that is invisible to the Windows Task List and to the fast ALT+TAB switching order.



MORE INFORMATION
All Visual Basic applications have a background window that handles all messages for the application and all calls to the VBRUN300.DLL. This background window is also the owner and parent of all non-MDI child forms. You can use the GetWindow and ShowWindow Windows API functions to hide this background window.

To be eligible for removal from the ALT+TAB order, an application cannot have any visible forms. The background window is visible, but you can use GetWindow to return the background or owner window's handle, and then use the handle and ShowWindow to make the window invisible.



Step-by-Step Example
This example hides itself from the Windows Task List and ALT+TAB order.

1. Start a New Project in Visual Basic. Form1 is created by default.

2. Add a timer control (Timer1) to the form.

3. Add the following declarations to the general declarations section:


   ' Enter each of the following Declare statements as one, single line:
   Declare Function ShowWindow Lib "User" (ByVal hWnd As Integer,
      ByVal nCmdShow As Integer) As Integer
   Declare Function GetWindow Lib "User" (ByVal hWnd As Integer,
      ByVal wCmd As Integer) As Integer
   Const SW_HIDE = 0
   Const GW_OWNER = 4


4. Add the following code to the load event of Form1:

   Sub Form_Load ()

      Dim OwnerhWnd As Integer
      Dim ret As Integer

      ' Make sure the form is invisible:
      form1.Visible = False

      ' Set interval for timer for 5 seconds, and make sure it is enabled:
      timer1.Interval = 5000
      timer1.Enabled = True

      ' Grab the background or owner window:
      OwnerhWnd = GetWindow(Me.hWnd, GW_OWNER)
      ' Hide from task list:
      ret = ShowWindow(OwnerhWnd, SW_HIDE)

   End Sub


5. Add the following code to the Timer event of the Timer1 control to
   verify that the program is running and to allow you to exit the program:

   Sub Timer1_Timer ()

      Dim ret As Integer

      ' Display a message box:
    ret = MsgBox("Visible by Alt+Tab. Cancel to Quit", 1, "Invisible Form")
      ' If cancel clicked, end the program:
      If ret = 2 Then
         timer1.Enabled = False
         Unload Me
         End
      End If

   End Sub


6. Save the project as INVIS.MAK and create an executable entitled
   INVIS.EXE.


7. Run the program by double-clicking INVIS.EXE in File Manager or by using
   the Run option in Program Manager. When you run the program, there
   should be no visible forms and the program title should not appear in
   the Task List or in the ALT+TAB order. After five seconds, the
   application should display the message box. Then the program should be
   visible to the ALT+TAB order, but not the Task List. Click the Cancel
   button to exit the application, or click OK to allow it to continue to
   run.

0
 
LVL 1

Expert Comment

by:mmips
ID: 2539985
And last but not least...I didn't send this earlier so I could get the right name ...goto www.planet-source-code.com
and search for :

Handling your own window messages...

This code allows you to trap all messages for your window...
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 1

Expert Comment

by:vasu_i
ID: 2539993
In Win 95 and 98, You can not prevent any application from being closed. But you can hide an application from being shown in the task list. Check the mmips's comment.

In Win NT, services can not be forced to quit. Check your VC samples for sample code on how to create a service.
0
 
LVL 32

Accepted Solution

by:
Erick37 earned 50 total points
ID: 2540119
Hiding Your Program in the Ctrl-Alt-Del list (Win 95/96)

http://www.vb-world.net/tips/tip135.html
0
 
LVL 32

Expert Comment

by:Erick37
ID: 2540121
Uh, that's Win 95/98
0
 
LVL 1

Author Comment

by:georgep23
ID: 2540301
purrrrfect!

thanks lots guy for your help!

(and girls if there are any on here!)
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now