Announcement

Collapse

Forum Guidelines

This forum is for finished source code that is working properly. If you have questions about this or any other source code, please post it in one of the Discussion Forums, not here.
See more
See less

Delete EXE of parent process

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Delete EXE of parent process

    Don't do it never in real live

    Code:
    #COMPILE EXE
    #DIM ALL
    '
    #INCLUDE "win32api.inc"
    #INCLUDE "TlHelp32.inc"
    '
    DECLARE FUNCTION GetModuleFileNameEx LIB "Psapi.dll" ALIAS "GetModuleFileNameExA" (BYVAL hProcess AS DWORD, BYVAL hModule AS DWORD, BYREF szReceiveToString AS ASCIIZ , BYVAL dwSizeOfString AS DWORD) AS DWORD
    '
    FUNCTION PBMAIN () AS LONG
      LOCAL MyPID,hSNAPPROCESS,hOfParent AS DWORD
      LOCAL lRes AS LONG
      DIM pe32 AS LOCAL PROCESSENTRY32
      LOCAL sParentsName AS ASCIIZ *%MAX_PATH
      '
      MyPID = GetCurrentProcessID() 'PID of us
      '
      hSNAPPROCESS = CreateToolhelp32Snapshot (BYVAL %TH32CS_SNAPPROCESS , BYVAL MyPID )
      '
      IF hSNAPPROCESS <> %INVALID_HANDLE_VALUE THEN
        pe32.dwSize = SIZEOF(pe32)
        lRes=Process32First(BYVAL hSNAPPROCESS,BYVAL VARPTR(pe32) )
        '
        IF ISTRUE (lRes) THEN
           WHILE lRes AND pe32.th32ProcessID<>MyPid
              lRes=Process32Next (BYVAL hSNAPPROCESS,BYVAL VARPTR(pe32) )
           WEND
           '
           hOfParent=OpenProcess(%PROCESS_QUERY_INFORMATION OR %PROCESS_VM_READ OR %SYNCHRONIZE ,0,pe32.th32ParentProcessID)
           '
           IF hOfParent<> 0 THEN
              IF GetModuleFileNameEx(hOfParent, 0, sParentsName, SIZEOF(sParentsName))<> 0 THEN
                 ? "your parent is : [PID="+STR$(pe32.th32ParentProcessID)+"] "+sParentsName+$CRLF+ _
                   "will be delete after your press OK."
                 WaitForSingleObject(hOfParent, %INFINITE)
                 'kill sParentsName
                 ? "unrem yourself previous line, I may not kill parents in any view  [img]http://www.powerbasic.com/support/forums/smile.gif[/img]"
              ELSE
                  ? "Ghm-sorry, your parent doesn't allow us to kill him"
              END IF
              CloseHandle(hOfParent)
           END IF
           '
        ELSE
           ? "Parent disappear  [img]http://www.powerbasic.com/support/forums/smile.gif[/img] "
        END IF
      '
      ELSE
          ? "Can't take handle of snapshot"
      END IF
      CloseHandle(hSNAPPROCESS)
      '
    END FUNCTION
    SY,

    ------------------
    -=Alex=-
    -=Alex=-
Working...
X