In Delphi, I started a program (FTP) with ShellExecute. Then I want to wait until the FTP process ends and continue the following operations. How can I monitor whether the process has ended?

Source: Internet
Author: User
In Delphi, I started a program (FTP) with ShellExecute. Then I want to wait until the FTP process ends and continue the following operations. How can I monitor whether the process has ended? Delphi/Windows SDK/API
Http://www.delphi2007.net/DelphiAPI/html/delphi_20061115114909229.html
Example:

Hinstance: = ShellExecute (application. Handle, nil, pchar ('ftp '), pchar ('-I-n-s: '+ scriptname), nil, sw_shownormal );
For I: = 0 to 10 do
Begin
Sleep 1000;
If ftp_end () then
Break;
End;

Use OpenProcess with waitforsingleobject.

Transferred

Execute an external Program And wait for it to finish.
Function winexecexw (CMD, workdir: pchar; visiable: integer): DWORD;
VaR
Startupinfo: tstartupinfo;
Processinfo: tprocessinformation;
Begin
Fillchar (startupinfo, sizeof (startupinfo), #0 );
Startupinfo. CB: = sizeof (startupinfo );
Startupinfo. dwflags: = startf_useshowwindow;
Startupinfo. wshowwindow: = visiable;
If not CreateProcess (nil, CMD, nil, nil, false, create_new_console or normal_priority_class, nil, nil, startupinfo, processinfo) then
Result: = 0
Else
Begin
Waitforsingleobject (processinfo. hprocess, infinite );
Getexitcodeprocess (processinfo. hprocess, result );
End;
End;

The waitforsingleobject function seems to have a problem in XP and will wait for it all the time. I am afraid to use it now ;;

Shellexectue returns the Process Handle. In theory, hinstance can be used to check its status, but it does not know how to do it!

It is better to use tidftp on your own.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.