Welcome to HBH! If you have tried to register and didn't get a verification email, please using the following link to resend the verification email.

disable "end task" for my program


ghost's Avatar
0 0

when I click "End task" in task manager, some programs do not terminate and show message telling me "access denied". how to code such programs? I think there exists a winapi function for this.


ghost's Avatar
0 0

i know a line of code that prevents the user from opening the task manager.. lemme check …… oooo i seem to have lost it :P Check codeguru.com, u can find sthg like app.taskvisible = false I THINK , n a shell command (i call it like that cz it has the word shell in it's code) that prevents alt+ctrl+del from opening the TM but this code can still close an app: (that's a VB module –not-written-by-me–)

Option Explicit
'on win2k you need the following:
Private Const PROCESS_TERMINATE = &H1

'On nt 9X the following could be enough:
Private Const PROCESS_ALL_ACCESS = &H1F0FFF

'in any case, let us use both...

'I thought this was 255, but was wrong...
Private Const MAX_PATH As Integer = 260


Private Type PROCESSENTRY32
  dwSize As Long
  cntUsage As Long
  th32ProcessID As Long
  th32DefaultHeapID As Long
  th32moduleID As Long
  cntThreads As Long
  th32ParentProcessID As Long
  pcPriClassBase As Long
  dwFlags As Long
  szExeFile As String * MAX_PATH
End Type

Private Declare Function CreateToolHelpSnapshot Lib "kernel32" Alias "CreateToolhelp32Snapshot" (ByVal lFlags As Long, ByVal lProcessID As Long) As Long

Private Declare Function ProcessFirst Lib "kernel32" Alias "Process32First" (ByVal hSnapShot As Long, uProcess As PROCESSENTRY32) As Long
Private Declare Function ProcessNext Lib "kernel32" Alias "Process32Next" (ByVal hSnapShot As Long, uProcess As PROCESSENTRY32) As Long

Private Declare Function TerminateProcess Lib "kernel32" (ByVal ApphProcess As Long, ByVal uExitCode As Long) As Long

Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long





Public Function KillApp(myName As String) As Boolean
 
    Dim uProcess As PROCESSENTRY32
    Dim rProcessFound As Long
    Dim hSnapShot As Long
    Dim szExename As String
    Dim exitCode As Long
    Dim myProcess As Long
    Dim iFound As Integer
    
    On Error GoTo ErrHandler
    
    Const TH32CS_SNAPPROCESS As Long = 2&
    
    uProcess.dwSize = Len(uProcess)
    hSnapShot = CreateToolHelpSnapshot(TH32CS_SNAPPROCESS, 0&)
    rProcessFound = ProcessFirst(hSnapShot, uProcess)


    Do While rProcessFound
       iFound = InStr(1, uProcess.szExeFile, Chr(0)) - 1
       If iFound > 0 Then
           szExename = LCase$(Left$(uProcess.szExeFile, iFound))
        
           If Right$(szExename, Len(myName)) = LCase$(myName) Then
               
               myProcess = OpenProcess(PROCESS_ALL_ACCESS Or PROCESS_TERMINATE, False, uProcess.th32ProcessID)
               KillApp = TerminateProcess(myProcess, exitCode)
               Call CloseHandle(myProcess)
               
                
               'if you have only one, exit here:
               'Exit Function
               'if you think you may have more than one,
               'let this go on
           End If
           rProcessFound = ProcessNext(hSnapShot, uProcess)
       End If
    Loop
    Call CloseHandle(hSnapShot)
    Exit Function
ErrHandler:
    'something went wrong. Let us exit
    MsgBox Err.Description
End Function

It's from a guy from planetsourcecode..


n3w7yp3's Avatar
Member
0 0

in Perl you can eaisly have your program ignore signals by doing somehting like:

$SIG{'INT'} = 'IGNORE';
$SIG{'HUP'} = 'IGNORE';
$SIG{'TERM'} = 'IGNORE';
$SIG{'CHLD'} = 'IGNORE';
$SIG{'PS'} = 'IGNORE';

note that there is no way to stop SIGKILL (kill -9).

edit: gah, looks like from your post you're on Windows, and this is for *nix. oh well, its still good to know ;)