windows获取系统补丁+匿名管道
void CSstemPatchDlg::OnBnClickedOk()
{
// TODO:? 在此添加控件通知處理程序代碼
// TODO: Add extra validation here??
SECURITY_ATTRIBUTES sa;
HANDLE hRead, hWrite;
sa.nLength = sizeof(SECURITY_ATTRIBUTES);
sa.lpSecurityDescriptor = NULL;? //使用系統默認的安全描述符? ?
sa.bInheritHandle = TRUE;? //創建的進程繼承句柄??
if (!CreatePipe(&hRead, &hWrite, &sa, 0))? //創建匿名管道??
{
MessageBox(_T("CreatePipe Failed!"), _T("Tip"), MB_OK | MB_ICONWARNING);
return;
}
STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory(&si, sizeof(STARTUPINFO));
si.cb = sizeof(STARTUPINFO);
GetStartupInfo(&si);
si.hStdError = hWrite;
si.hStdOutput = hWrite;? //新創建進程的標準輸出連在寫管道一端??
si.wShowWindow = SW_HIDE;? //隱藏窗口? ? ?
si.dwFlags = STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES;
TCHAR cmdline[256] = { _T("systeminfo.exe") };
//CString tmp,stredit2;??
//? GetDlgItemText(IDC_EDIT2,stredit2);? //獲取編輯框中輸入的命令行??
//? tmp.Format(_T("cmd /C %s"),stredit2);??
//? _stprintf(cmdline,_T("%s"),tmp);??
#ifdef _UNICODE??
//MessageBox(_T("UNICODE!"), _T("提示"), MB_OK | MB_ICONWARNING);??
#else??
//MessageBox(_T("ANSI!"), _T("提示"), MB_OK | MB_ICONWARNING);??
#endif??
if (!CreateProcess(NULL, cmdline, NULL, NULL, TRUE, NULL, NULL, NULL, &si, &pi))? //創建子進程??
{
MessageBox(_T("CreateProcess Failed!"), _T("Tip"), MB_OK | MB_ICONWARNING);
return;
}
CloseHandle(hWrite);? //關閉管道句柄??
char buffer[4096] = { 0 };
CString strOutput;
CString PatchKB = { _T("KB4012212111") };
DWORD bytesRead;
while (true)
{
if (ReadFile(hRead, buffer, 4095, &bytesRead, NULL) == NULL)? //讀取管道??
break;
strOutput += buffer;
SetDlgItemText(IDC_EDIT1, strOutput);? //顯示輸出信息到編輯框,并刷新窗口??
//AfxMessageBox(strOutput);??
//UpdateWindow();??
//Sleep(100);??
}
if (_tcsstr(strOutput, PatchKB))
{
AfxMessageBox(_T("Pass"));
}
else
AfxMessageBox(_T("Fail"));
CloseHandle(hRead);
CDialogEx::OnOK();
}
總結
以上是生活随笔為你收集整理的windows获取系统补丁+匿名管道的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 两个大数相乘实例
- 下一篇: C/C++面试题—链表中倒数第k个结点