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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
| HANDLE PipeIn;
HANDLE PipeOut;
TSecurityAttributes Securite;
TStartupInfo StartupInfo;
TProcessInformation ProcessInfo;
CheckListBox1->Visible = false;
stateSend->Visible = true;
STARTUPINFO si;
PROCESS_INFORMATION pi;
BOOL b = false;
si.wShowWindow = SW_HIDE;
si.hStdInput = &PipeIn;
si.hStdOutput= &PipeOut;
si.hStdError = &PipeOut;
ZeroMemory(&si, sizeof(STARTUPINFO));
si.cb = sizeof (STARTUPINFO);
ZeroMemory(&pi, sizeof (PROCESS_INFORMATION));
char result[300] = "\0";
char parametre[200] = "\0";
char parametre2[100] = "\0";
DWORD NbRead;
String str;
for(int i = 0; i < CheckListBox1->Count; i++)
{
if(CheckListBox1->State[i] == true)
{
CreatePipe(&PipeIn,&PipeOut,&Securite,0);
AnsiString ping = "ping -n 1 " + CheckListBox1->Items->Strings[i];
strcpy(parametre2, ping.c_str());
//On teste avant tout que l'on puisse communiquer avec la machine
b = CreateProcess(NULL, parametre2, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
WaitForSingleObject(pi.hProcess,INFINITE);
CloseHandle(PipeOut);
while(ReadFile(&PipeIn, result, 300, &NbRead, NULL))
{
str = result;
}
CloseHandle(PipeIn);
CreatePipe(&PipeIn,&PipeOut,&Securite,0);
if(b)
{
stateSend->Font->Color = clBlue;
stateSend->Text = stateSend->Text + "Ping " + ping + " reussi...\r\n\r\n";
AnsiString texte = CheckListBox1->Items->Strings[i];
texte = texte.Trim();
//exemple pscp.exe -l root -pw root 127.0.0.1:C:\\File C:\\File
AnsiString param = "pscp.exe -l " + UserCh->Text + " -pw " + MdpCh->Text + " " + texte + ":"+ OpenDialog1->FileName + " " + Sortie->Text;
strcpy(parametre, param.c_str());
b = CreateProcess(NULL, parametre, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
WaitForSingleObject(pi.hProcess,INFINITE);
CloseHandle(PipeOut);
while(ReadFile(&PipeIn, result, 300, &NbRead, NULL))
{
str = result;
}
CloseHandle(PipeIn);
if(b)
{
stateSend->Font->Color = clBlue;
stateSend->Text = stateSend->Text + "Transfert vers machine " + CheckListBox1->Items[i].Text.Trim() + " reussi...\r\n\r\n";
}
else
{
stateSend->Font->Color = clRed;
stateSend->Text = stateSend->Text + "Transfert vers machine " + CheckListBox1->Items[i].Text.Trim() + " code KO...\r\n\r\n" ;
}
}
else
{
stateSend->Font->Color = clRed;
stateSend->Text = stateSend->Text + "Ping " + ping + " Code KO...\r\n\r\n";
}
} |
Partager