Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. CreateProcess() not working

CreateProcess() not working

Scheduled Pinned Locked Moved C / C++ / MFC
help
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Member 4201820
    wrote on last edited by
    #1

    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!!!

    C _ S 3 Replies Last reply
    0
    • M Member 4201820

      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!!!

      C Offline
      C Offline
      CPallini
      wrote on last edited by
      #2

      "is not working" is a poor report. Could you please tell use more? Moreover, in the two different tests (namely command line and CreateProcess call) why don't you give exactly the same arguments to Rehash?

      Veni, vidi, vici.

      1 Reply Last reply
      0
      • M Member 4201820

        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!!!

        _ Offline
        _ Offline
        _Superman_
        wrote on last edited by
        #3

        Look at the documentation of CreateProcess[^] Now look carefully at the difference between the first and second parameter types - LPCTSTR and LPTSTR 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)

        Polymorphism in C

        1 Reply Last reply
        0
        • M Member 4201820

          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!!!

          S Offline
          S Offline
          Software_Developer
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups