Forum
|
|
ShellExecute does not work right, use CreateProcess, get handle of process & use WaitForSingleObject
|
Vortex |
|
Extremely Active Member
Group: Moderators
Posts: 129
Member No.: 8
Joined: 13-May 04
|
Shoorick is right, WaitForSingleObject can do the job :
CODE | .486 ; create 32 bit code .model flat, stdcall ; 32 bit memory model option casemap :none ; case sensitive
include \masm32\include\windows.inc include \masm32\include\kernel32.inc
.code
;----------------------------------------------------------------------------; ; This is a translation of a shell script originally written by Edgar Hansen; ; in GoASM code. Translation by Paul E. Brennick <[email protected]> ; ; ; ; Shell: This function will run an executable and wait until it has ; ; finished before continuing. The function provides for a time ; ; out for a maximum wait period. ; ; Parameters: lpfilename = The fully qualified path to an executable to run ; ; dwTimeOut = The amount of time in milliseconds to wait, -1 for; ; no timeout ; ; Returns: 0 if successful, STATUS_TIMEOUT if the timeout has elapsed ; ; -1 if there was an error creating the process ; ; ; ;----------------------------------------------------------------------------; Shell PROC lpfilename:DWORD, dwTimeOut:DWORD LOCAL Sh_st_info :STARTUPINFO LOCAL Sh_pr_info :PROCESS_INFORMATION
mov DWORD PTR [Sh_st_info.cb], SIZEOF STARTUPINFO invoke GetStartupInfoA, ADDR Sh_st_info mov DWORD PTR [Sh_st_info.lpReserved], 0 invoke CreateProcessA, 0, [lpfilename], 0, 0, 0, 0, 0, 0, \ ADDR Sh_st_info, ADDR Sh_pr_info test eax, eax jz ERROR invoke WaitForSingleObject, [Sh_pr_info.hProcess], [dwTimeOut] push eax invoke CloseHandle, [Sh_pr_info.hThread] invoke CloseHandle, [Sh_pr_info.hProcess] pop eax test eax, eax RET ERROR: xor eax, eax sub eax, 1 RET Shell ENDP
end
|
|
|
|
|
Slider |
|
Extremely Active Member
Group: Moderators
Posts: 179
Member No.: 5004
Joined: 11-May 07
|
I can not figure out how to use Shell correctly.
Some things are confusing.
lpfilename name is declared as a DWORD when it really is a byte value.
Thanks.
CODE | Shell PROTO :DWORD, :DWORD
.data
lpfilename DWORD "E:\Bat\bak1.bat",0 dwTimeOut DWORD 15000 ; Allow 15 seconds before timing out
.code
start:
main proc
invoke Shell,ADDR lpfilename, ADDR dwTimeOut invoke ExitProcess,NULL
main endp
;----------------------------------------------------------------------------; ; This is a translation of a shell script originally written by Edgar Hansen; ; in GoASM code. Translation by Paul E. Brennick <[email protected]> ; ; ; ; Shell: This function will run an executable and wait until it has ; ; finished before continuing. The function provides for a time ; ; out for a maximum wait period. ; ; Parameters: lpfilename = The fully qualified path to an executable to run; ; dwTimeOut = The amount of time in milliseconds to wait, -1 for; ; no timeout ; ; Returns: 0 if successful, STATUS_TIMEOUT if the timeout has elapsed ; ; -1 if there was an error creating the process ; ; ; ;----------------------------------------------------------------------------; Shell PROC lpfilename:DWORD, dwTimeOut:DWORD
LOCAL Sh_st_info :STARTUPINFO LOCAL Sh_pr_info :PROCESS_INFORMATION
mov DWORD PTR [Sh_st_info.cb], SIZEOF STARTUPINFO invoke GetStartupInfoA, ADDR Sh_st_info mov DWORD PTR [Sh_st_info.lpReserved], 0 invoke CreateProcessA, 0, [lpfilename], 0, 0, 0, 0, 0, 0, \ ADDR Sh_st_info, ADDR Sh_pr_info test eax, eax;ObjectToWaitOn jz ERROR invoke WaitForSingleObject, [Sh_pr_info.hProcess], [dwTimeOut] push eax invoke CloseHandle, [Sh_pr_info.hThread] invoke CloseHandle, [Sh_pr_info.hProcess] pop eax test eax, eax RET ERROR: xor eax, eax sub eax, 1 RET Shell ENDP
end start |
|
|
|
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:
Track this topic
Receive email notification when a reply has been made to this topic and you are not active on the board.
Subscribe to this forum
Receive email notification when a new topic is posted in this forum and you are not active on the board.
Download / Print this Topic
Download this topic in different formats or view a printer friendly version.
|
|
|