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 );