Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <windows.h>
- #include <stdio.h>
- DWORD dwError;
- #define DEBUG puts("DEBUG");
- INT WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, INT nCmdShow)
- {
- SECURITY_ATTRIBUTES Sa;
- Sa.nLength = sizeof(SECURITY_ATTRIBUTES);
- Sa.bInheritHandle = TRUE;
- Sa.lpSecurityDescriptor = NULL;
- LPTSTR lpCmd = "C:\\Windows\\System32\\cmd.exe";
- HANDLE hRead;
- HANDLE hWrite;
- STARTUPINFO Si;
- PROCESS_INFORMATION Pi;
- ZeroMemory(&Si, sizeof(STARTUPINFO));
- ZeroMemory(&Pi, sizeof(PROCESS_INFORMATION));
- if(!CreatePipe(&hRead, &hWrite, &Sa, 0))
- goto FAILURE;
- if(!SetHandleInformation(hRead, HANDLE_FLAG_INHERIT, 0))
- goto FAILURE;
- Si.cb = sizeof(STARTUPINFO);
- Si.hStdError = hWrite;
- Si.hStdOutput = hWrite;
- Si.hStdInput = hRead;
- Si.dwFlags |= STARTF_USESTDHANDLES;
- if(!CreateProcess(lpCmd, NULL, NULL, NULL, TRUE, 0, NULL, NULL, &Si, &Pi))
- goto FAILURE;
- TCHAR tBuffer[4096];
- DWORD dwRead = 0;
- if(!ReadFile(hRead, tBuffer, 4096, &dwRead, NULL))
- goto FAILURE;
- TerminateProcess(Pi.hProcess, ERROR_SUCCESS);
- puts(tBuffer);
- return ERROR_SUCCESS;
- FAILURE:
- dwError = GetLastError();
- printf("%ld\r\n", dwError);
- return dwError;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement