hi...
i'm trying to send a string to windows cmd so that it can run the command contained in the string.
i'm using CreateProcess() to send known windows command lines (ex: net user, net localgroup, at, etc), and it works fine. But now i want to send a script (ex: echo test > test.txt) and it doesn't work
Can anyone help me?
Here is my CreateProcess() function:
Code:int runScripts(char str[]) { PROCESS_INFORMATION pi; STARTUPINFO si; ZeroMemory(&si, sizeof(STARTUPINFO)); si.cb=sizeof(STARTUPINFO); /* si.cbReserved2 = 0; si.dwFillAttribute = 0; si.dwFlags = 0; si.dwX = 0; si.dwXCountChars = 0; si.dwXSize = 0; si.dwY = 0; si.dwYCountChars = 0; si.dwYSize = 0; si.dwY = 0; si.dwYCountChars = 0; si.hStdError = NULL; si.hStdInput = NULL; si.hStdOutput = NULL; si.lpDesktop = NULL; si.lpReserved = NULL; si.lpReserved2 = NULL; si.lpTitle = NULL; si.wShowWindow = 0; */ if (CreateProcess("C:\\Windows\\System32\\cmd.exe", (LPSTR) str, NULL, NULL, 0, 0, NULL, NULL, &si, &pi)) { CloseHandle(pi.hProcess); CloseHandle(pi.hThread); return 1; //success } else { CloseHandle(pi.hProcess); CloseHandle(pi.hThread); return 0; //failure } }