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 problem.

CreateProcess problem.

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
9 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.
  • I Offline
    I Offline
    iLoveM
    wrote on last edited by
    #1

    A.exe use createprocess to start up B.exe, B.exe must read a local file in its folder, i found i only click B.exe, B.exe can open the local file, when A.exe start up B.exe using createprocess, B.exe fails to open the local file always. Why? Just relax

    N H D I 4 Replies Last reply
    0
    • I iLoveM

      A.exe use createprocess to start up B.exe, B.exe must read a local file in its folder, i found i only click B.exe, B.exe can open the local file, when A.exe start up B.exe using createprocess, B.exe fails to open the local file always. Why? Just relax

      N Offline
      N Offline
      Naveen
      wrote on last edited by
      #2

      how do u try to open the file? Try opening the the file using the full path not relative. I doubt the problem happens because of the change in the working directory of the b.exe. nave

      I 1 Reply Last reply
      0
      • I iLoveM

        A.exe use createprocess to start up B.exe, B.exe must read a local file in its folder, i found i only click B.exe, B.exe can open the local file, when A.exe start up B.exe using createprocess, B.exe fails to open the local file always. Why? Just relax

        H Offline
        H Offline
        Hamid Taebi
        wrote on last edited by
        #3

        Can you show how to use._**


        **_

        whitesky


        I 1 Reply Last reply
        0
        • N Naveen

          how do u try to open the file? Try opening the the file using the full path not relative. I doubt the problem happens because of the change in the working directory of the b.exe. nave

          I Offline
          I Offline
          iLoveM
          wrote on last edited by
          #4

          I have try both full path and relative, but have the same problem. Just relax

          1 Reply Last reply
          0
          • H Hamid Taebi

            Can you show how to use._**


            **_

            whitesky


            I Offline
            I Offline
            iLoveM
            wrote on last edited by
            #5

            Main process: STARTUPINFO si; ZeroMemory(&si, sizeof(si)); si.cb = sizeof STARTUPINFO; PROCESS_INFORMATION pi; CreateProcess("A.exe", NULL, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi); Sub Process: GetModuleFileName(NULL,read,1000); printf("%s\n",read); int len = strlen(read); strcpy(read+len-4,".tmp"); printf("%s\n",read); FILE *f = fopen(read,"rb"); if (f==NULL) { printf("Hello world\n"); } Just relax

            N D 2 Replies Last reply
            0
            • I iLoveM

              Main process: STARTUPINFO si; ZeroMemory(&si, sizeof(si)); si.cb = sizeof STARTUPINFO; PROCESS_INFORMATION pi; CreateProcess("A.exe", NULL, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi); Sub Process: GetModuleFileName(NULL,read,1000); printf("%s\n",read); int len = strlen(read); strcpy(read+len-4,".tmp"); printf("%s\n",read); FILE *f = fopen(read,"rb"); if (f==NULL) { printf("Hello world\n"); } Just relax

              N Offline
              N Offline
              Naveen
              wrote on last edited by
              #6

              iLoveM wrote:

              FILE *f = fopen(read,"rb");

              u try opening the file in write mode. if that too failes, u can conclude one of the following 1. A file already exist in that path and is been opened by another process 2. Path is invalid 3. Don't have privilage and let me know the results nave

              1 Reply Last reply
              0
              • I iLoveM

                A.exe use createprocess to start up B.exe, B.exe must read a local file in its folder, i found i only click B.exe, B.exe can open the local file, when A.exe start up B.exe using createprocess, B.exe fails to open the local file always. Why? Just relax

                D Offline
                D Offline
                David Crow
                wrote on last edited by
                #7

                iLoveM wrote:

                Why?

                You should be telling us why. :confused: If you are opening the file via CreateFile() and it's failing, what does GetLastError() return?


                "The largest fire starts but with the smallest spark." - David Crow

                "Judge not by the eye but by the heart." - Native American Proverb

                1 Reply Last reply
                0
                • I iLoveM

                  Main process: STARTUPINFO si; ZeroMemory(&si, sizeof(si)); si.cb = sizeof STARTUPINFO; PROCESS_INFORMATION pi; CreateProcess("A.exe", NULL, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi); Sub Process: GetModuleFileName(NULL,read,1000); printf("%s\n",read); int len = strlen(read); strcpy(read+len-4,".tmp"); printf("%s\n",read); FILE *f = fopen(read,"rb"); if (f==NULL) { printf("Hello world\n"); } Just relax

                  D Offline
                  D Offline
                  David Crow
                  wrote on last edited by
                  #8

                  iLoveM wrote:

                  FILE *f = fopen(read,"rb");

                  If fopen() fails, what is the value of errno?


                  "The largest fire starts but with the smallest spark." - David Crow

                  "Judge not by the eye but by the heart." - Native American Proverb

                  1 Reply Last reply
                  0
                  • I iLoveM

                    A.exe use createprocess to start up B.exe, B.exe must read a local file in its folder, i found i only click B.exe, B.exe can open the local file, when A.exe start up B.exe using createprocess, B.exe fails to open the local file always. Why? Just relax

                    I Offline
                    I Offline
                    iLoveM
                    wrote on last edited by
                    #9

                    It's too strange!!! STARTUPINFO si; ZeroMemory(&si, sizeof(si)); si.cb = sizeof STARTUPINFO; CHAR szFolderWhereFileIsLocated[250]={0}; strcpy(szFolderWhereFileIsLocated ,"put path here"); PROCESS_INFORMATION pi; CreateProcess("A.exe", NULL, NULL, NULL, FALSE, 0, NULL, szFolderWhereFileIsLocated, &si, π); when i put these code in a console program, the sub process can open correctly. Then in my windows program, the sub process can't open file firstly, then start up the sub process again (my program will start up the sub process every 20 sec) , it's OK. Just relax

                    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