CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Thread: Regd. Winexec..

  1. #1
    Join Date
    Jul 2004
    Posts
    10

    Regd. Winexec..

    hi ppl.

    In order to run an executable application .exes in a program you could always have the option of Winexec as well as Create process...But I find it some what time consuming when i use it.Is it really so and are there any other faster methods than this..

    thanx in advance,

    nash.

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Regd. Winexec..

    Quote Originally Posted by nashs
    hi ppl.

    In order to run an executable application .exes in a program you could always have the option of Winexec as well as Create process...But I find it some what time consuming when i use it.Is it really so and are there any other faster methods than this..

    thanx in advance,

    nash.
    What do you mean by "faster methods"?
    There are only two (or three -?) methods to "run an executable application .exes in a program" in Win 32:
    CreateProcess
    ShellExecute
    (and ShellExecuteEx)

  3. #3
    Join Date
    Jun 2004
    Posts
    1,352

    Re: Regd. Winexec..

    Are you running the DEBUG or Release version??

    What are you doing up intialization??

  4. #4
    Join Date
    Jul 2004
    Posts
    10

    Re: Regd. Winexec..

    I am using a release version....actually i have a "recv.exe filename.ext" which i use to retrieve the file from any network....I want to execute this command recieve the file and then read data from it. I use winexec("recv filename.ext") but i needed to have a sleep after that so that it gets copied to a path and then i open it...is it possible to reduce this time...

    my code looks as below...

    WinExec("recv.exe C:\\sendanth.txt",SW_HIDE);
    Sleep(350);
    //Variable assignment for reading the file
    char temp[13];
    CString dump;

    CFile te;
    te.Open.....

    regs.
    nash

  5. #5
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Regd. Winexec..

    This is from MSDN (CreateProcess):
    Remarks
    The CreateProcess function is used to run a new program. The WinExec and LoadModule functions are still available, but they are implemented as calls to CreateProcess.
    In addition to creating a process, CreateProcess also creates a thread object. The thread is created with an initial stack whose size is described in the image header of the specified program's executable file. The thread begins execution at the image's entry point.

    When created, the new process and the new thread handles receive full access rights. For either handle, if a security descriptor is not provided, the handle can be used in any function that requires an object handle to that type. When a security descriptor is provided, an access check is performed on all subsequent uses of the handle before access is granted. If access is denied, the requesting process cannot use the handle to gain access to the thread.
    ........................
    ...........................

    The calling thread can use the WaitForInputIdle function to wait until the new process has finished its initialization and is waiting for user input with no input pending. This can be useful for synchronization between parent and child processes, because CreateProcess returns without waiting for the new process to finish its initialization. For example, the creating process would use WaitForInputIdle before trying to find a window associated with the new process.
    Thus, call WaitForInputIdle instead of Sleep.
    As for "to reduce this time" - the time you wait is (almost) equal the time Windows starts / initializes you process.

  6. #6
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652

    Re: Regd. Winexec..

    Quote Originally Posted by VictorN
    There are only two (or three -?) methods to "run an executable application .exes in a program" in Win 32:
    CreateProcess
    ShellExecute
    (and ShellExecuteEx)
    Well..actually there are some more...as shown on the following FAQ...

  7. #7
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652

    Re: Regd. Winexec..

    Quote Originally Posted by nashs
    I use winexec("recv filename.ext") but i needed to have a sleep after that so that it gets copied to a path and then i open it...is it possible to reduce this time...
    Well...I do not know what 'recv' does, however, if you need to wait until the newly created process becomes idle, you can use the function 'WaitForInputIdle()' as indicated by VictorN...
    Code:
    STARTUPINFO         siStartupInfo;
    PROCESS_INFORMATION piProcessInfo;
    
    memset(&siStartupInfo, 0, sizeof(siStartupInfo));
    memset(&piProcessInfo, 0, sizeof(piProcessInfo));
    
    siStartupInfo.cb = sizeof(siStartupInfo);
    
    if(CreateProcess("c:\\windows\\notepad.exe", // Application name
                     " example.txt",             // Application arguments
                     0,
                     0,
                     FALSE,
                     CREATE_DEFAULT_ERROR_MODE,
                     0,
                     0,                          // Working directory
                     &siStartupInfo,
                     &piProcessInfo) == FALSE)
      // Could not start application -> call 'GetLastError()'
    
    // Wait for new process becoming idle
    if(::WaitForInputIdle(piProcessInfo.hProcess, INFINITE))
      // Error occured -> call '::GetLastError()'
    else
      // Process is idle
    However, if you need to wait until the process 'recv' did something after becoming idle (waiting for the file or whatever), the above will not give you the desired result. In this case, I would suggest using some kind of interprocess communication to trigger the parent process as soon as the file has been created, received or...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured