Use Win32 API CreateProcess () to create a DOS program without a window

Source: Internet
Author: User

DoSProgramThere are two possibilities:

First, when creating the DOS process, specify not to create a window;

Second, there is a window to hide the DOS process.

According to msdn, the CreateProcess () API prototype is as follows:

Bool CreateProcess (

Lptstr lpapplicationname,

Lptstr lpcommandline,

Lpsecurity_attributes lpprocessattributes,

Lpsecurity_attributes lpthreadattributes,

Bool binherithandles,

DWORD dwcreationflags,

Lpvoid lpenvironment,

Maid directory,

Lpstartupinfo,

Lpprocess_information lpprocessinformation

);

Specify dwcreationflagsCreate_no_window

,Create a DOS process without creating a window.

The lpstartupinfo parameter is in the startupinfo structure again, as follows:

Typedef struct _ startupinfo {

Dword cb;

Lptstr lpreserved;

Lptstr lpdesktop;

Lptstr lptitle;

DWORD dwx;

DWORD dwy;

DWORD dwxsize;

DWORD dwysize;

DWORD dwxcountchars;

DWORD dwycountchars;

DWORD dwfillattribute;

DWORD dwflags;

Word wshowwindow;

Word cbreserved2;

Lpbyte lpreserved2;

Handle hstdinput;

Handle hstdoutput;

Handle hstderror;

} Startupinfo, * lpstartupinfo;

Specify the word wshowwindow in the startupinfo structure as sw_hide, that is, the DOS process is created in the non-display window mode.

In visusl Studio 2005, the test result is: Create a [CMD/C] dos process. The first method is to create a DOS process without a window, the second method does not properly hide the DOS window.

An instance for service installation:

Cstring scommand = "+ sserviceexefilepath +" + "" + "-install ";

Startupinfo Si;
Process_information PI;
Memset (& Si, 0, sizeof (SI ));
Si. cb = sizeof (SI );
If (CreateProcess (null, (char *) (lpctstr) scommand), null, null, false, 0, null, null, & Si, & PI ))
{
Waitforsingleobject (PI. hprocess, infinite );
Bret = true;
}

Closehandle (PI. hthread );
Closehandle (PI. hprocess );

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.