call external.exe
if external is not running
terminate myself
if external is not running
terminate myself
CreateProcess
start like this:
1.find handle of exe in memory
a. if found, jump @end
b. if not found...
2.call exe to start
a. if sucesfull open, jump @end
b. if not, wait some time and jump again to 2
3.end:
terminate
:lol:
1.find handle of exe in memory
a. if found, jump @end
b. if not found...
2.call exe to start
a. if sucesfull open, jump @end
b. if not, wait some time and jump again to 2
3.end:
terminate
:lol:
Finding a process that is running on your system is not as easy as it might appear, you can ofcourse just find the window using FindWindow but if the other process does not have a GUI element then you're rooked. The most reliable way I can think of is to walk all of the processes looking for the one you want. This is an example of a process walk for NT/2K/XP/2K3 only as it uses NTDLL.DLL...
Returns -1 if the process was not found, otherwise it returns the PID.
FindProcessByNameNT FRAME pszProcess,StartID
uses edi,esi,ebx
LOCAL pProcessSnap :D
LOCAL buffer[256] :W
mov edi,
sub eax,eax
mov ecx,256
repne scasb
not cl
or ecx,ecx
jnz >
sub eax,eax
dec eax
ret
:
mov al, "\"
std
repne scasb
cld
add edi,2
or ecx,ecx
jnz >
mov edi,
:
// Use unicode strings
invoke MultiByteToWideChar,0,0,edi,-1,offset buffer,256
invoke VirtualAlloc,0,020000h,MEM_COMMIT,PAGE_READWRITE
mov ,eax
mov esi,eax
or eax,eax
jnz >
sub eax,eax
dec eax
ret
:
invoke NtQuerySystemInformation,5,esi,20000h,0
; Find our processID
mov esi,
L0:
mov ebx,
cmp ebx,
jle >L1
; Do a quick compare to weed out the impossible ones by
; checking the first 2 characters to see if they match
lea eax, buffer
mov eax,
mov ecx,
or ecx,ecx
jz >L1
mov ecx,
cmp eax,ecx
jne >L1
invoke lstrcmpiW,,offset buffer
jz >.FOUND
L1:
mov eax,
add esi,eax
or eax,eax
jnz <L0
dec eax
push eax
jmp >.DONE
.FOUND
push ebx
.DONE
invoke VirtualFree,,0,MEM_RELEASE
pop eax
or eax,eax
RET
ENDF
Returns -1 if the process was not found, otherwise it returns the PID.
To find the process you can use EnumProcesses or CreateToolhelp32Snapshot. There's a tutorial for the latter.
Both methods work on XP and 2k but only EnumProcesses on NT4 and only CreateToolhelp32Snapshot on 9x.
Both methods work on XP and 2k but only EnumProcesses on NT4 and only CreateToolhelp32Snapshot on 9x.
asmd,
Welcome on board.
You can embed external executables in your main module , there are some occasions to do it :
http://www.asmcommunity.net/board/index.php?topic=21210.0
Welcome on board.
You can embed external executables in your main module , there are some occasions to do it :
http://www.asmcommunity.net/board/index.php?topic=21210.0
Did someone say eggdrop?
Spawn the child program with CreateProcess. Check return value, terminate on error. CloseHandle on process_information.hThread. WaitForSingleObject on process_information.hProcess with INFINITE timeout. If WaitForSingleObject returns, the child process has terminated.
...And perhaps be a bit more clearer about what you want to do :)
...And perhaps be a bit more clearer about what you want to do :)