Use code to start the EXE file

Source: Internet
Author: User

Void readfile (cstring filename) // path for storing the EXE file in the filename path file. Multiple EXE files can be started at a time.

{
// Tchar szbuf [1024];
File * pfile = fopen (filename, "R"); // open the file
Exesl = 0;
Int I = 0, n = 0;
Char Buf [1024];
While (! Feof (pfile ))
{
Fgets (BUF, 1024, pfile); // read a row (including the carriage return at the end of the row) to the Buf
N = strlen (BUF );
If (BUF [n-1] = '\ n') // remove the last line and press Enter.
Buf [n-1] = '\ 0 ';
Strcpy (A [I], Buf); // each row is stored in the corresponding string array.
// Afxmessagebox (A [I]);
I ++;
}
Exesl = I;
// Getdlgitem (idc_send)-> setwindowtext (szbuf); // write control
Fclose (pfile); // close the file
}
Void openexe ()
{
Int I;

For (I = 0; I <exesl; I ++)
{
// Open the specified application file
// Afxmessagebox (A [I]);
Startupinfo Si = {sizeof (SI )};
Process_information PI;
Si. dwflags = startf_useshowwindow; // specify that the wshowwindow member is valid.
Si. wshowwindow = true; // if this member is set to true, the main window of the new process is displayed.
Bool Bret = CreateProcess (
Null, // The Name Of The executable file is not specified here
A [I], // command line parameters
Null, // default process security
Null, // default process security
False, // specifies that the current process handle cannot be inherited by the quilt Process
Create_new_console, // create a new console window for the new process
Null, // use the environment variable of this Process
Null, // use the drive and directory of the current process
& Si,
& PI );
If (BRET)
{
// Disable unused handles.
Closehandle (PI. hthread );
Closehandle (PI. hprocess );
Exeid [I] = pi. dwprocessid;
}
}
}

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.