News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

ShellExecute

Started by clamicun, January 05, 2017, 02:35:40 AM

Previous topic - Next topic

clamicun

INVOKE ShellExecute,0,offset fOpen,offset file2execute,offset param,NULL,SW_HIDE   

On success ShellExecute  returns  > 32

But what I need is the exitcode of the executed file.
Is there a possibility ?     

nidud

#1
deleted

hutch--

These are the return values.

0  The operating system is out of memory or resources.
ERROR_FILE_NOT_FOUND  The specified file was not found.
ERROR_PATH_NOT_FOUND  The specified path was not found.
ERROR_BAD_FORMAT  The .exe file is invalid (non-Win32® .exe or error in .exe image).
SE_ERR_ACCESSDENIED  The operating system denied access to the specified file. 
SE_ERR_ASSOCINCOMPLETE  The file name association is incomplete or invalid.
SE_ERR_DDEBUSY  The DDE transaction could not be completed because other DDE transactions were being processed.
SE_ERR_DDEFAIL  The DDE transaction failed.
SE_ERR_DDETIMEOUT  The DDE transaction could not be completed because the request timed out.
SE_ERR_DLLNOTFOUND  The specified dynamic-link library was not found. 
SE_ERR_FNF  The specified file was not found. 
SE_ERR_NOASSOC  There is no application associated with the given file name extension. This error will also be returned if you attempt to print a file that is not printable.
SE_ERR_OOM  There was not enough memory to complete the operation.
SE_ERR_PNF  The specified path was not found.
SE_ERR_SHARE  A sharing violation occurred.

clamicun

nidud ... thank you ... I check it out

hutch ... thank you ... like I said > 32 on success or the described errcodes 

hutch--

Yes, sorry about that, you can set the exit code as an argument for ExitProcess() and to get it from another app nidud has given you the answer, from the console a batch file with get the error level.

adeyblue

You can use ShellExecuteEx with the SEE_MASK_NOCLOSEPROCESS flag (It's something like that, I'm going from memory), it's basically the same as ShellExecute except you fill a structure instead of passing arguments. Then use GetExitCodeProcess as mentioned above, before closing the handle when you're done.

There isn't a way to get it just using ShellExecute sincec it just starts the process and forgets about it.

clamicun

adeyblue, I am working on this-

INVOKE GetExitCodeProcess,ShExecInfo.hProcess,offset exitcode   ;handle from ShellExecuteEx
The handle must have the PROCESS_QUERY_INFORMATION ???
You have an idea ?

Vortex

Hi clamicun,

Walking the table of processes, you can get the ID of the process matching the executable name in question. The attachment contains a demo project. Terminating the process SimpleWnd.exe, you will see a message box displaying the exit code.

include GetProcessExitCode.inc

.data

fname   db 'SimpleWnd.exe',0
title1  db 'ExitCode',0
msg     db 'SimpleWnd = %d',0

.data?

sei             SHELLEXECUTEINFO <?>
hProcessSnap    dd ?
pe32            PROCESSENTRY32 <?>
pID             dd ?
ExitCode        dd ?
buffer          db 64 dup(?)

.code

start:

    call    main
    invoke  ExitProcess,0

main PROC uses esi edi

    mov     esi,OFFSET sei
    xor     eax,eax
    mov     SHELLEXECUTEINFO.cbSize[esi],\
            SIZEOF SHELLEXECUTEINFO
           
    mov     SHELLEXECUTEINFO.fMask[esi],\
            SEE_MASK_NOCLOSEPROCESS
           
    mov     SHELLEXECUTEINFO.hwnd[esi],eax
    mov     SHELLEXECUTEINFO.lpFile[esi],OFFSET fname
    mov     SHELLEXECUTEINFO.lpParameters[esi],eax
    mov     SHELLEXECUTEINFO.lpDirectory[esi],eax
    mov     SHELLEXECUTEINFO.nShow[esi],SW_SHOWNORMAL
    mov     SHELLEXECUTEINFO.hInstApp[esi],eax

    invoke  ShellExecuteEx,esi

    lea     edi,pe32
    invoke  CreateToolhelp32Snapshot,TH32CS_SNAPPROCESS,0
    mov     hProcessSnap,eax
    mov     pe32.dwSize,SIZEOF(PROCESSENTRY32)
    invoke  Process32First,eax,edi
@@:
    lea     eax,PROCESSENTRY32.szExeFile[edi]

    invoke  lstrcmpi,eax,ADDR fname
    test    eax,eax
    jz      get_pID

    invoke  Process32Next,hProcessSnap,edi
    test    eax,eax
    jnz     @b

get_pID:

    push    PROCESSENTRY32.th32ProcessID[edi]
    pop     pID

    invoke  CloseHandle,hProcessSnap

    invoke  OpenProcess,PROCESS_QUERY_INFORMATION,0,pID
    invoke  CloseHandle,eax

    invoke  WaitForSingleObject,SHELLEXECUTEINFO.hProcess[esi],\
            INFINITE

    invoke  GetExitCodeProcess,SHELLEXECUTEINFO.hProcess[esi],\
            ADDR ExitCode
           
    invoke  wsprintf,ADDR buffer,ADDR msg,ExitCode
    invoke  MessageBox,0,ADDR buffer,ADDR title1,MB_OK

    ret
   
main ENDP

END start

clamicun

vorex, thanks,
looks good, but I can't assemble it, because I don't know where I find Pelles lib.

clamicun


clamicun

Vortex,
yes runs well.
Thanks