| 454 | } |
| 455 | |
| 456 | QString WinUtils::executeBlockingCmd(QString cmd, const QString & /*params*/, int timeoutMs) |
| 457 | { |
| 458 | QString result = ""; |
| 459 | |
| 460 | SECURITY_ATTRIBUTES sa; |
| 461 | ZeroMemory(&sa,sizeof(sa)); |
| 462 | sa.nLength = sizeof(sa); |
| 463 | sa.bInheritHandle = TRUE; |
| 464 | |
| 465 | HANDLE rPipe, wPipe; |
| 466 | if (!CreatePipe(&rPipe, &wPipe, &sa, 0)) |
| 467 | { |
| 468 | return result; |
| 469 | } |
| 470 | |
| 471 | STARTUPINFO si; |
| 472 | PROCESS_INFORMATION pi; |
| 473 | ZeroMemory( &si, sizeof(si) ); |
| 474 | si.cb = sizeof(si); |
| 475 | si.dwFlags |= STARTF_USESTDHANDLES; |
| 476 | si.hStdInput = NULL; |
| 477 | si.hStdError = wPipe; |
| 478 | si.hStdOutput = wPipe; |
| 479 | |
| 480 | ZeroMemory( &pi, sizeof(pi) ); |
| 481 | if (CreateProcess(NULL, (wchar_t *) cmd.toStdWString().c_str(), NULL, NULL, TRUE, CREATE_NO_WINDOW | NORMAL_PRIORITY_CLASS, NULL, NULL, &si, &pi)) |
| 482 | { |
| 483 | DWORD exitCode; |
| 484 | if (timeoutMs < 0) |
| 485 | { |
| 486 | exitCode = WaitForSingleObject(pi.hProcess, INFINITE); |
| 487 | } |
| 488 | else |
| 489 | { |
| 490 | exitCode = WaitForSingleObject(pi.hProcess, timeoutMs); |
| 491 | } |
| 492 | |
| 493 | CloseHandle(wPipe); |
| 494 | std::string str; |
| 495 | str = readAllFromPipe(rPipe); |
| 496 | CloseHandle(rPipe); |
| 497 | CloseHandle( pi.hProcess ); |
| 498 | CloseHandle( pi.hThread ); |
| 499 | |
| 500 | result = QString::fromStdString(str); |
| 501 | } |
| 502 | else |
| 503 | { |
| 504 | qCCritical(LOG_BASIC) << "Failed create process: %x", GetLastError(); |
| 505 | CloseHandle(rPipe); |
| 506 | CloseHandle(wPipe); |
| 507 | } |
| 508 | return result; |
| 509 | } |
| 510 | |
| 511 | bool WinUtils::isServiceRunning(const QString &serviceName) |
| 512 | { |
nothing calls this directly
no test coverage detected