首页
社区
课程
招聘
用CreateToolhelp32Snapshot检测进程是否存在的问题
发表于: 2008-12-28 03:50 6486

用CreateToolhelp32Snapshot检测进程是否存在的问题

2008-12-28 03:50
6486
崩溃
用记事本测试
用快照检测是否存在notepad.exe如果不存在则运行,按推理即便是系统中不存在notepad.exe这个进程,也只会运行一次。因为运行一次后系统中就有notepad.exe这个进程了
我没说错吧?
可下面这个程序,执行后notepad.exe一个又一个的弹出来。。。汗。。。
————————————————————————
同样用notepad.exe作测试,只是把那个WinExec换成MessageBox又一切正常,可以达到预期的效果。。。

刚学,很菜的问题,别笑啊

还有个问题,如果循环用快照枚举进程会产生一定的页面错误增量。。。在网上找到下答案,虽说没多大影响但看着终究不爽。。。
在网上找了些同样用快照循环枚举进程的程序,有些没有页面错误增量。。。怎么解决的?

.386
.model flat,stdcall
option casemap:none

include        windows.inc
include        user32.inc
include        kernel32.inc
includelib     user32.lib
includelib     kernel32.lib
;_________________________________________________________
.data?
hInstance        dd        ?
hProcess        dd        ?
hSnapShot        dd        ?
stProcess        PROCESSENTRY32        <?>

.const
scCmd                db        'notepad.exe',0
sc                db        'c:\windows\notepad.exe',0
;_______
.code
;_____________________________________________________________
_Process        Proc
                invoke        CreateToolhelp32Snapshot,TH32CS_SNAPPROCESS,0
                mov        hSnapShot,eax
                invoke RtlZeroMemory,addr stProcess,sizeof PROCESSENTRY32
                mov        stProcess.dwSize,sizeof stProcess
                invoke        Process32First,hSnapShot,offset stProcess
        .while         eax
                mov        esi,FALSE
                invoke        lstrcmp,addr scCmd,addr stProcess.szExeFile
        .if        eax == 0
                ;invoke        OpenProcess,PROCESS_ALL_ACCESS,FALSE,stProcess.th32ProcessID
                ;invoke        TerminateProcess,eax,-1
                mov        esi,TRUE
                .break             
        .endif
               
                invoke        Process32Next,hSnapShot,addr stProcess
        .endw
                invoke        CloseHandle,hSnapShot
               
        .if        esi != TRUE
                ;invoke        MessageBox,0,addr sc,0,MB_OK
                                ;这儿换成MessageBox运行正常
                invoke        WinExec,addr sc,SW_SHOWNORMAL
        .endif
                ret
_Process        endp
;_________________________________________________________
start:
                call        _Process
               
                invoke        Sleep,1000
                jmp        start             
                invoke        ExitProcess,NULL
end start

[培训]内核驱动高级班,冲击BAT一流互联网大厂工作,每周日13:00-18:00直播授课

收藏
免费 0
支持
分享
最新回复 (2)
雪    币: 130
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
2
start:
    call  _Process // run notepad.exe after kill notepad.exe
   
    invoke  Sleep,1000
    jmp  start  // next 'run notepad.exe after kill notepad.exe'
2008-12-28 11:02
0
雪    币: 196
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
3
多谢,改成while就好了
2008-12-28 13:36
0
游客
登录 | 注册 方可回帖
返回
//