In the program, I started another program with winexec. How can I determine when the program will end?

Source: Internet
Author: User
Execute with shellexcute
Use waitforsingleobject to wait for its end
---------------------------------------------------------------

How to start Program Until it stops running?
Shellexecuteinfo shexecinfo = {0 };
Shexecinfo. cbsize = sizeof (shellexecuteinfo );
Shexecinfo. fmask = see_mask_nocloseprocess;
Shexecinfo. hwnd = NULL;
Shexecinfo. lpverb = NULL;
Shexecinfo. lpfile = "C: \ myprogram.exe ";
Shexecinfo. lpparameters = "";
Shexecinfo. lpdirectory = NULL;
Shexecinfo. nshow = sw_show;
Shexecinfo. hinstapp = NULL;
Shellexecuteex (& shexecinfo );
Waitforsingleobject (shexecinfo. hprocess, infinite );

Or:

Process_information processinfo;
Startupinfo; // This is an [in] Parameter
Zeromemory (& startupinfo, sizeof (startupinfo ));
Startupinfo. cb = sizeof startupinfo; // only compulsory field
If (CreateProcess ("C: \ winnt \ notepad.exe", null,
Null, null, false, 0, null,
Null, & startupinfo, & processinfo ))
{
Waitforsingleobject (processinfo. hprocess, infinite );
Closehandle (processinfo. hthread );
Closehandle (processinfo. hprocess );
}
Else
{
MessageBox ("the process cocould not be started ...");
}

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.