ShellExecute after another ShellExecute 
Author Message
 ShellExecute after another ShellExecute

I have a program, program.exe
I want to run program1.exe using the ShellExecuteA call from program.exe
When program1.exe is done executing, I then want to call program2.exe from
program.exe, using the same method.

Here's what I have so far:

--------------------------------------------------------------------------
-------
bits 32
extern   __imp_ShellExecuteA ;from shell32.lib

global _login

section .text use32

_login:       ;coff entrypoint

        push    dword 0               ;    INT nShowCmd
        push    dword 0               ;    LPCTSTR lpDirectory
        push    dword 0               ;    LPCTSTR lpParameters
        push    dword program1   ;    LPCTSTR lpFile
        push    dword 0               ;      LPCTSTR lpVerb
        push    dword 0               ;    HWND hwnd
        call    [__imp_ShellExecute]

        push    dword 0                  ;    INT nShowCmd
        push    dword 0                   ;    LPCTSTR lpDirectory
        push    dword 0                   ;    LPCTSTR lpParameters
        push    dword program2       ;    LPCTSTR lpFile
        push    dword 0                   ;   LPCTSTR lpVerb
        push    dword 0                   ;    HWND hwnd
        call    [__imp_ShellExecute]

        sub      eax, eax

        ret

program1 db  'c:\program1.exe', 0
program2 db  'c:\program2.exe', 0
----------------------------------------------------------
compiled with 'nasm -fcoff program.asm'
      - produces program.o
linked with 'alink -oPE program.o -entry _login'
      - produces program.exe

I then run program.exe;  Program1 and Program2 start up normally without any
errors or anything, but program2 executes while program1 is running, but I want
it to wait for program1 to finish executing [calling ExitProcess or whatever]
before it starts executing.
What must I do to make this happen?



Wed, 25 Sep 2002 03:00:00 GMT  
 ShellExecute after another ShellExecute

Quote:
> I then run program.exe;  Program1 and Program2 start up normally without
any
> errors or anything, but program2 executes while program1 is running, but I
want
> it to wait for program1 to finish executing [calling ExitProcess or
whatever]
> before it starts executing.
> What must I do to make this happen?

Sorry, this is off-topic, but now I also little program inWin. Yes, this is
totally nightmare (example can't get HD manufacturer-serial-nr, MFC
bugs.....etc).
I was experiment with ShellExecute and ShellExecuteEx, but those
functions don't WAIT program execution. Instead I use '_spawnv()'.
But I notice that '_spawnv()' hang my NT in some very strange moments,
in most cases it work.(after I 'kill' this process with NT-manager, all
again OK)

--
  Ivar, (c)RMSoft
  http://my.tele2.ee/rmsoft



Thu, 26 Sep 2002 03:00:00 GMT  
 ShellExecute after another ShellExecute

Hi,
[snip]

Quote:
> I then run program.exe;  Program1 and Program2 start up normally
> without any errors or anything, but program2 executes while
> program1 is running, but I want it to wait for program1 to finish
> executing [calling ExitProcess or whatever] before it starts
> executing.
> What must I do to make this happen?

    I think that the C program below does what you want.

#include <windows.h>
TCHAR szCmdLine1[] = TEXT("c:\\windows\\winmine.exe");
TCHAR szCmdLine2[] = TEXT("c:\\windows\\sol.exe");
BOOL ExecAppAsync( TCHAR *szAppName, TCHAR *szCmdLine);

int WINAPI WinMain( HINSTANCE hInstance,
            HINSTANCE hPrevInstance, PSTR szCmdLine,
            int iCmdShow)
        {
        int     exCode = 1;
        if (ExecAppAsync( NULL, szCmdLine1))
                if (ExecAppAsync( NULL, szCmdLine2))
                        exCode = 0;
        return exCode;
        }

BOOL    ExecAppAsync( TCHAR *szAppName,
                                            TCHAR *szCmdLine)
        {
        STARTUPINFO             si;
        PROCESS_INFORMATION     pi;
        DWORD                   processExitCode;

        si.cb = sizeof( STARTUPINFO);
        si.lpReserved = 0;
        si.lpDesktop = NULL;
        si.lpTitle = NULL;
        si.dwFlags = 0;
        si.cbReserved2 = 0;
        si.lpReserved2 = NULL;

        if (!CreateProcess(szAppName, szCmdLine, NULL, NULL,
                                         FALSE, NORMAL_PRIORITY_CLASS,
                                         NULL, NULL, &si, &pi))
                {
                MessageBox(NULL, szCmdLine,
                                         TEXT("Couldn't exec program"),
                                         MB_OK);
                return FALSE;
                }

        do
                GetExitCodeProcess(pi.hProcess, &processExitCode);
        while   (processExitCode == STILL_ACTIVE);
        return  TRUE;
        }

regards,
-Brent
doomsday AT optusnet DOT com DOT au



Fri, 27 Sep 2002 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. ShellExecute problem

2. Printing Multiple copies using ShellExecute API Function

3. How to implement ShellExecute

4. Shellexecute

5. ShellExecute API with NT doesn't work?

6. Sample ShellExecute(hide window&wait) in Clarion5?

7. Are there known problems w/shellexecute on XP?

8. shellexecute in 16 and 32 bit

9. shellexecute to URL - how to determine target?

10. Equivalent of RUN('File',1) with ShellExecute

11. shellexecute WITH parameters

12. ShellExecute with MailTo

 

 
Powered by phpBB® Forum Software