#define execdoscmd "ping
Www.sohu.com "/ / can be replaced with your command
BOOL EXECDOSCMD ()
{
Security_attributes sa;
Handle Hread, hwrite;
Sa.nlength = sizeof (security_attributes);
Sa.lpsecurityDescriptor = null;
Sa.binherithandle = true;
IF (! Cread, & Hwrite, & Sa, 0))
{
Return False;
}
Startupinfo Si;
Process_information pi;
Si.cb = sizeof (startupinfo);
GetStartupInfo (& Si);
Si.hstderRor = hwrite;
Si.hstdoutput = hwrite;
Si.WShowWindow = sw_hide;
Si.dwflags = startf_useshowwindow | Startf_usestdhandles;
// Key step, createprocess function parameter meanings please check MSDN
IF (! CreateProcess (Null, Execdoscmd
NULL, NULL, TRUE, NULL, NULL, NULL, & SI, & PI)
{
Return False;
}
CloseHandle (HWRITE);
CHAR BUFFER [4096] = {0};
DWORD BYTESREAD;
OFSTREAM OFST;
OFST.OPEN ("cmd.txt");
While (True)
{
IF (readfile (Hread, Buffer, 4095, & Bytesread, NULL) == NULL)
Break;
// Buffer is the result of execution, can be saved to text, or directly output
// Printf (buffer);
Ofst << Buffer;
Sleep (200);
}
OFST.CLOSE ();
Return True;
}