#include #include #include #define SECURITY_WIN32 #include #include int main(int argc, char *argv[]) { // Dummy functions to force linking to specific libs // user32.lib IsCharAlpha('a'); // wsock32.lib WSADATA wsaData; WSAStartup(MAKEWORD(1, 1), &wsaData); // secur32.lib char un[30]; DWORD dwUNLen = 30; GetUserNameExA(NameUserPrincipal, un, &dwUNLen); // advapi32.dll char un2[30]; DWORD dwUN2Len = 30; GetUserNameA(un2, &dwUN2Len); // shell32.dll IsUserAnAdmin(); // Used by child processes if (argc == 1) { while (1) { printf("Foo\n"); Sleep(2000); } } else { for (int x=0; x<100; x++) { STARTUPINFOA si; PROCESS_INFORMATION pi; memset(&pi, 0, sizeof(pi)); memset(&si, 0, sizeof(si)); si.cb = sizeof(si); /* * Create the subprocess in a suspended state. This will be resumed later, * once we have written out the parameter file. */ printf("Creating process %d...\n", x); if (!CreateProcessA(NULL, argv[0], NULL, NULL, TRUE, CREATE_SUSPENDED, NULL, NULL, &si, &pi)) { printf("CreateProcess call failed: %m (error code %d)", (int) GetLastError()); return -1; } printf("Resuming thread %d...\n", x); if (ResumeThread(pi.hThread) == -1) { if (!TerminateProcess(pi.hProcess, 255)) { printf("could not terminate unstartable process: error code %d", (int) GetLastError()); CloseHandle(pi.hProcess); CloseHandle(pi.hThread); return -1; } CloseHandle(pi.hProcess); CloseHandle(pi.hThread); printf("could not resume thread of unstarted process: error code %d", (int) GetLastError()); return -1; } } } return 0; }