WinAsm Studio, The Assembly IDE - Free Downloads, Source Code
Sponsors
Articles
Programming Quick Start
32-bit Assembler is Easy
Porting Iczelion tutorials
What is FASM
Hard Drive Recovery
Wiring your own LAN
Personal menu
Welcome Guest
User:
Pass:
Register!
Resend Validation Email
 
Forum
 

Detect if an application runs and terminate it, using CreateToolhelp32Snapshot with TH32CS_SNAPPROCESS and comparing PROCESSENTRY32.szExeFile with application exe name.

Slider
Quote Post


Extremely Active Member
******

Group: Moderators
Posts: 287
Member No.: 5004
Joined: 11-May 07


Sometime I would like to learn how to have this prog detect when online and then run this code.

Thanks.

CODE
; killbart1.asm    
; Help from Tedd,sinsi,Nordwind64,Herbert,...
;
; Terminates bartshel.exe!!
; (A badly behaved program no longer needed after connection.)
;
;  FREEWARE, but not finished yet :-)
;
;  Future plans:  Detect when connected and run 10 secs after connection

.586
.model flat, stdcall
option casemap:none
include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
includelib \masm32\lib\kernel32.lib
include \masm32\include\user32.inc
includelib \masm32\lib\user32.lib

.data
AppName         db "Terminate",0
nice_guy        db "bartshel.exe",0

errSnapshot     db "CreateToolhelp32Snapshot failed.",0
errProcFirst    db "Process32First failed.",0

.data?
hSnapshot   HANDLE ?
ProcEnt     PROCESSENTRY32 <?>

.code
start:
   invoke CreateToolhelp32Snapshot, TH32CS_SNAPPROCESS,0
   .IF (eax != INVALID_HANDLE_VALUE)
       mov hSnapshot,eax
       mov [ProcEnt.dwSize],SIZEOF ProcEnt
       invoke Process32First, hSnapshot,ADDR ProcEnt
       .IF (eax)
         @@:
           invoke lstrcmpi, ADDR nice_guy ,ADDR [ProcEnt.szExeFile]
           .IF (eax == 0)
               invoke OpenProcess, PROCESS_TERMINATE,FALSE,[ProcEnt.th32ProcessID]
               .IF (eax)
                   invoke TerminateProcess, eax,0
               .ELSE
               ;failed for some reason
               .ENDIF
           .ENDIF
           invoke Process32Next, hSnapshot,ADDR ProcEnt
           test eax,eax
           jnz @B
       .ELSE
           invoke MessageBox, NULL,ADDR errProcFirst,ADDR AppName,MB_OK or MB_ICONERROR
       .ENDIF
       invoke CloseHandle, hSnapshot
   .ELSE
       invoke MessageBox, NULL,ADDR errSnapshot,ADDR AppName,MB_OK or MB_ICONERROR
   .ENDIF
   invoke ExitProcess, NULL
end start

PMEmail Poster
Top
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

Topic Options Reply to this topicStart new topicStart Poll

 

Sponsors
Computer Science

Internet
C/C++
Hardware & PC maintenance

HiEditor

General Discussions
Suggestions/Bug Reports
WinAsm Studio

General Discussions
Suggestions/Bug Reports
WinAsm Studio FAQ
Multilingual User Interface
Add-Ins
Assembly Programming

Main
Newbies
Projects
Custom Controls
Snippets
Announcements & Rules

Announcements

General

Online Degrees - Distance Learning
The Heap
Russian
Google