CreateProcess() not working
-
Hi All, my objective is to create a .MD5 file using Rehash.exe which will be called by CreatedProcess(). if i run from command line its working fine C:\temp>rehash.exe -none -md5 "C:\temp\aaa.TFI" > "C:\temp\aaa.MD5" but if i implement in code and use CreateProcess, its not working below is the code snippet int main() { STARTUPINFO si; PROCESS_INFORMATION pi; ZeroMemory( &si, sizeof(si) ); si.cb = sizeof(si); ZeroMemory( &pi, sizeof(pi) ); LPSTR lp_rehashEXE = "C:\\temp\\rehash.exe"; LPSTR lp_Parameter = " -none -md5 C:\\temp\\Praveer.TFI > C:\\temp\\Praveer.MD5"; if(!::CreateProcess(lp_rehashEXE, lp_Parameter, NULL, NULL, false, 0, NULL, NULL, &si, &pi)) { printf( "CreateProcess failed (%d)\n", GetLastError() ); return false; } // Wait until child process exits. ::WaitForSingleObject(pi.hProcess, INFINITE ); // Close process handles. CloseHandle( pi.hProcess ); return 0; } Please help!!!
-
Hi All, my objective is to create a .MD5 file using Rehash.exe which will be called by CreatedProcess(). if i run from command line its working fine C:\temp>rehash.exe -none -md5 "C:\temp\aaa.TFI" > "C:\temp\aaa.MD5" but if i implement in code and use CreateProcess, its not working below is the code snippet int main() { STARTUPINFO si; PROCESS_INFORMATION pi; ZeroMemory( &si, sizeof(si) ); si.cb = sizeof(si); ZeroMemory( &pi, sizeof(pi) ); LPSTR lp_rehashEXE = "C:\\temp\\rehash.exe"; LPSTR lp_Parameter = " -none -md5 C:\\temp\\Praveer.TFI > C:\\temp\\Praveer.MD5"; if(!::CreateProcess(lp_rehashEXE, lp_Parameter, NULL, NULL, false, 0, NULL, NULL, &si, &pi)) { printf( "CreateProcess failed (%d)\n", GetLastError() ); return false; } // Wait until child process exits. ::WaitForSingleObject(pi.hProcess, INFINITE ); // Close process handles. CloseHandle( pi.hProcess ); return 0; } Please help!!!
-
Hi All, my objective is to create a .MD5 file using Rehash.exe which will be called by CreatedProcess(). if i run from command line its working fine C:\temp>rehash.exe -none -md5 "C:\temp\aaa.TFI" > "C:\temp\aaa.MD5" but if i implement in code and use CreateProcess, its not working below is the code snippet int main() { STARTUPINFO si; PROCESS_INFORMATION pi; ZeroMemory( &si, sizeof(si) ); si.cb = sizeof(si); ZeroMemory( &pi, sizeof(pi) ); LPSTR lp_rehashEXE = "C:\\temp\\rehash.exe"; LPSTR lp_Parameter = " -none -md5 C:\\temp\\Praveer.TFI > C:\\temp\\Praveer.MD5"; if(!::CreateProcess(lp_rehashEXE, lp_Parameter, NULL, NULL, false, 0, NULL, NULL, &si, &pi)) { printf( "CreateProcess failed (%d)\n", GetLastError() ); return false; } // Wait until child process exits. ::WaitForSingleObject(pi.hProcess, INFINITE ); // Close process handles. CloseHandle( pi.hProcess ); return 0; } Please help!!!
Look at the documentation of CreateProcess[^] Now look carefully at the difference between the first and second parameter types -
LPCTSTR
andLPTSTR
respectively. The first is a constant string and the second is not a constant. In your code, you're using a pointer to a read-only memory location, which is like a constant string. Here is an excerpt from the documentation - The Unicode version of this function, CreateProcessW, can modify the contents of this string. Therefore, this parameter cannot be a pointer to read-only memory (such as a const variable or a literal string).«_Superman_» _I love work. It gives me something to do between weekends.
_Microsoft MVP (Visual C++) (October 2009 - September 2013)
-
Hi All, my objective is to create a .MD5 file using Rehash.exe which will be called by CreatedProcess(). if i run from command line its working fine C:\temp>rehash.exe -none -md5 "C:\temp\aaa.TFI" > "C:\temp\aaa.MD5" but if i implement in code and use CreateProcess, its not working below is the code snippet int main() { STARTUPINFO si; PROCESS_INFORMATION pi; ZeroMemory( &si, sizeof(si) ); si.cb = sizeof(si); ZeroMemory( &pi, sizeof(pi) ); LPSTR lp_rehashEXE = "C:\\temp\\rehash.exe"; LPSTR lp_Parameter = " -none -md5 C:\\temp\\Praveer.TFI > C:\\temp\\Praveer.MD5"; if(!::CreateProcess(lp_rehashEXE, lp_Parameter, NULL, NULL, false, 0, NULL, NULL, &si, &pi)) { printf( "CreateProcess failed (%d)\n", GetLastError() ); return false; } // Wait until child process exits. ::WaitForSingleObject(pi.hProcess, INFINITE ); // Close process handles. CloseHandle( pi.hProcess ); return 0; } Please help!!!
It works, you just dont have rehash.exe in C.\temp I compiled your code and it and it worked. Output:
Line, Character counting Program === === by Newbie
Usage: fileName
EXE Path:Press any key to continue