Results 1 to 12 of 12

Thread: Prevent users from terminating an application???

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2002
    Posts
    91

    Question Prevent users from terminating an application???

    Hi guys,

    I have an application which runs on server, which I do not want to be terminated (using ctrl+alt+del) by the users.

    Since the application generates report and also works as query pad, I don't not want to hide the application using 'RegisterServiceProcess'!!!

    I have seen applications where when the users try to terminate an application they are asked for password and only then they are allowed to shut down the application.

    How do I achieve this???

    Thanks
    Subhendu.

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    VB Code:
    1. Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    2. 'enter code for password here.   if password is valid, allow the shutdown
    3. 'if password is invalid, issue a Cancel = -1 to terminate the shutdown
    4. End Sub

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jul 2002
    Posts
    91
    Hi Hack,

    Thanks for your suggestion.

    But, I still have problem areas!!!

    The moment I ask the user to enter the password, the windows shows that the application has stopped responding and asks the user to 'End Task', 'Wait', 'Cancel' the process.

    Plus, I find usually by Ctrl+Alt+Del many times allows the application to be terminated!!!

    I DO need more help !!!

    Thanks.

  4. #4
    Lively Member
    Join Date
    Feb 2002
    Location
    India
    Posts
    83

    Re:Stop Termination

    Why don't you restrict user from using the (ctl +alt+del) all the way !.
    Use,
    SystemParametersInfo API,and use its serv. No (97) to restrict termination Window from Windows

  5. #5
    Next Of Kin baja_yu's Avatar
    Join Date
    Aug 2002
    Location
    /dev/root
    Posts
    5,989
    Hi,

    this is an old thread but I have a similar need.
    Is there a way to prevent it from being terminated, not only by users (ctrl+alt+delete) but by other apps too?

    I am trying to build a security application which I dont want being terminated by malicious applications like trojans and viruses.

  6. #6
    Junior Member
    Join Date
    May 2004
    Posts
    20
    Try hidding it from the application list.

  7. #7
    Next Of Kin baja_yu's Avatar
    Join Date
    Aug 2002
    Location
    /dev/root
    Posts
    5,989
    Yes, but I think it still does get listed as a process and it can be found there and terminated.

  8. #8
    Hyperactive Member Jlarini's Avatar
    Join Date
    Jan 2002
    Location
    São Paulo, Brazil
    Posts
    263
    Hi, guys!!!

    I had a problem sometime ago, where I need to catch when the user tries to close an app. So I used this...

    I Hope it can help....


    VB Code:
    1. Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" _
    2.     (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal MSG As Long, _
    3.     ByVal wParam As Long, ByVal lParam As Long) As Long
    4.    
    5. Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _
    6.     (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
    7.    
    8. Declare Function GetMessage Lib "user32" Alias "GetMessageA" _
    9.     (lpMsg As MSG, ByVal hwnd As Long, ByVal wMsgFilterMin As Long, _
    10.     ByVal wMsgFilterMax As Long) As Long
    11.    
    12.    
    13. Type POINTAPI
    14.     X As Long
    15.     y As Long
    16. End Type
    17.  
    18. Type MSG
    19.     hwnd    As Long
    20.     message As Long
    21.     wParam  As Long
    22.     lParam  As Long
    23.     time    As Long
    24.     pt      As POINTAPI
    25. End Type
    26.  
    27. Public Const GWL_WNDPROC = -4
    28. Public Const WM_QUERYENDSESSION = &H11
    29. Public Const WM_CANCELMODE = &H1F
    30.  
    31. Public SDAttempt        As Long
    32. Global lpPrevWndProc    As Long
    33. Global gHW              As Long
    34.  
    35. Dim sSql    As String
    36.  
    37. 'Holds on
    38. Public Sub Hook()
    39.     lpPrevWndProc = SetWindowLong(gHW, GWL_WNDPROC, AddressOf WindowProc)
    40. End Sub
    41.  
    42. 'Lets close
    43. Public Sub Unhook()
    44.     Dim temp    As Long
    45.     temp = SetWindowLong(gHW, GWL_WNDPROC, lpPrevWndProc)
    46. End Sub
    47.  
    48. Function WindowProc(ByVal hw As Long, ByVal uMsg As Long, _
    49.     ByVal wParam As Long, ByVal lParam As Long) As Long
    50.    
    51.     Dim a As Long
    52.    
    53.     If uMsg = WM_QUERYENDSESSION Then
    54.         'your code here
    55.         hook
    56.     End If
    57.     WindowProc = CallWindowProc(lpPrevWndProc, hw, uMsg, wParam, lParam)
    58.    
    59. End Function

    JL
    nothing is impossible, it's sometimes very hard to do!

    If your thread is solved... Please edit it and add [Resolved] or [Solved] on it!

    If you like Marine aquarium, feel free to PM me.

    Sorry my bad English

    God bless Parksie!

  9. #9
    Next Of Kin baja_yu's Avatar
    Join Date
    Aug 2002
    Location
    /dev/root
    Posts
    5,989
    How is this code used?

  10. #10
    Hyperactive Member Jlarini's Avatar
    Join Date
    Jan 2002
    Location
    São Paulo, Brazil
    Posts
    263
    baja,

    When I used this code, I had problems because, some users just shuts down (using Start, shutdown) without close my app, and as I control who's using it, I need that when it closes that, the app saves it in a table... (such as an Yes/No field)...


    The hook, activate an "catch" that controls if the app is been closed and then made something you want, and then you need to unhook to let it close... (I used it sometime ago, so I don't remember exactly how it acts, but its something like that...)


    I'll take a look on my app, so I can answer more correctly. OK ?

    edit: Yes, as I said before it works that way...

    When you start your app, you need to Hook when you start your app, and to close the app you need to Unhook on MDIForm_Unload / Form_Unload.

    One possible problem... If you're in debuggin, comment Hook's line, cos, often, it crashes VB.... It's a pain ass, but... It works fine...



    JL
    Last edited by Jlarini; Aug 18th, 2004 at 02:03 PM.
    nothing is impossible, it's sometimes very hard to do!

    If your thread is solved... Please edit it and add [Resolved] or [Solved] on it!

    If you like Marine aquarium, feel free to PM me.

    Sorry my bad English

    God bless Parksie!

  11. #11
    Next Of Kin baja_yu's Avatar
    Join Date
    Aug 2002
    Location
    /dev/root
    Posts
    5,989
    Ok. Thanks.

  12. #12
    Next Of Kin baja_yu's Avatar
    Join Date
    Aug 2002
    Location
    /dev/root
    Posts
    5,989
    Ok. Thanks.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width