1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
|
int Commande::Executer(){
Form1->Label1->Caption = this->cmd;
DWORD codeSortie;
int valeurRetour = 0;
STARTUPINFO infoDemarrage;
PROCESS_INFORMATION infoProcessus;
memset(&infoDemarrage, 0, sizeof(TStartupInfo));
memset(&infoProcessus, 0, sizeof(TProcessInformation));
infoDemarrage.cb = sizeof(TStartupInfo);
infoDemarrage.dwFlags = STARTF_USESHOWWINDOW;
infoDemarrage.lpTitle = this->cmd.c_str();
if (invisible)
infoDemarrage.wShowWindow = SW_HIDE;
else
infoDemarrage.wShowWindow = SW_SHOWNORMAL;
if(CreateProcess(NULL, this->cmd.c_str(), NULL, NULL, 0, CREATE_DEFAULT_ERROR_MODE
,NULL, NULL, &infoDemarrage, &infoProcessus)){
GetExitCodeProcess(&infoProcessus.hProcess, &codeSortie);
while(WaitForSingleObject(infoProcessus.hProcess, 0)==WAIT_TIMEOUT){
Application->ProcessMessages();
GetExitCodeProcess(&infoProcessus.hProcess, &codeSortie);
}
}
else
valeurRetour = GetLastError();
CloseHandle(infoProcessus.hProcess);
CloseHandle(infoProcessus.hThread);
return valeurRetour;
} |
Partager