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 doesn't work while ShellExecute Does!!!!

CreateProcess doesn't work while ShellExecute Does!!!!

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
9 Posts 5 Posters 3 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.
  • Y Offline
    Y Offline
    YaronNir
    wrote on last edited by
    #1

    Hi all, I want to run ACDSee from create process this is the code i use:

    STARTUPINFOW si;
    PROCESS_INFORMATION pi;
    ZeroMemory(&pi,sizeof(PROCESS_INFORMATION));
    ZeroMemory(&si,sizeof(STARTUPINFO));
    si.cb = sizeof(STARTUPINFOW);
    si.wShowWindow = 1; // show
    if(!CreateProcessW(L"C:\\Program Files\\ACD Systems\\ACDSee\\6.0\\ACDSee6.exe",
    L"C:\\Program Files\\ACD Systems\\ACDSee\\6.0\\ACDSee6.exe",
    NULL,
    NULL,
    FALSE,
    0,
    NULL,
    NULL,
    &si,
    &pi))
    {
    ASSERT(FALSE);// failure
    }

    // success

    ok , the above code seems ok, but the problem is i pass the create process sucessfully, and i can't see any ACDSEE window open (nor i can't see the process in the task manager).... if i use this substitue code:

    ShellExecuteW(NULL,
    L"open",
    L"C:\\Program Files\\ACD Systems\\ACDSee\\6.0\\ACDSee6.exe",
    NULL,
    NULL,
    SW_SHOWNORMAL);

    it is working ok and ACDSEE is opened. i can't use ShellExecute because i need some process information which PROCESS_INFORMATION structure holds.... can any1 help? thanks in advanced Yaron Ask not what your application can do for you, Ask what you can do for your application

    C G D D 4 Replies Last reply
    0
    • Y YaronNir

      Hi all, I want to run ACDSee from create process this is the code i use:

      STARTUPINFOW si;
      PROCESS_INFORMATION pi;
      ZeroMemory(&pi,sizeof(PROCESS_INFORMATION));
      ZeroMemory(&si,sizeof(STARTUPINFO));
      si.cb = sizeof(STARTUPINFOW);
      si.wShowWindow = 1; // show
      if(!CreateProcessW(L"C:\\Program Files\\ACD Systems\\ACDSee\\6.0\\ACDSee6.exe",
      L"C:\\Program Files\\ACD Systems\\ACDSee\\6.0\\ACDSee6.exe",
      NULL,
      NULL,
      FALSE,
      0,
      NULL,
      NULL,
      &si,
      &pi))
      {
      ASSERT(FALSE);// failure
      }

      // success

      ok , the above code seems ok, but the problem is i pass the create process sucessfully, and i can't see any ACDSEE window open (nor i can't see the process in the task manager).... if i use this substitue code:

      ShellExecuteW(NULL,
      L"open",
      L"C:\\Program Files\\ACD Systems\\ACDSee\\6.0\\ACDSee6.exe",
      NULL,
      NULL,
      SW_SHOWNORMAL);

      it is working ok and ACDSEE is opened. i can't use ShellExecute because i need some process information which PROCESS_INFORMATION structure holds.... can any1 help? thanks in advanced Yaron Ask not what your application can do for you, Ask what you can do for your application

      C Offline
      C Offline
      Cedric Moonen
      wrote on last edited by
      #2

      Not sure if this will work but the second argument of CreateProcess is the commandline parameters that will be sent to the program. So, replace it by NULL and try again.

      Y 1 Reply Last reply
      0
      • C Cedric Moonen

        Not sure if this will work but the second argument of CreateProcess is the commandline parameters that will be sent to the program. So, replace it by NULL and try again.

        Y Offline
        Y Offline
        YaronNir
        wrote on last edited by
        #3

        doesn't work.... any other suggestion? anyone else? thanks Yaron Ask not what your application can do for you, Ask what you can do for your application

        1 Reply Last reply
        0
        • Y YaronNir

          Hi all, I want to run ACDSee from create process this is the code i use:

          STARTUPINFOW si;
          PROCESS_INFORMATION pi;
          ZeroMemory(&pi,sizeof(PROCESS_INFORMATION));
          ZeroMemory(&si,sizeof(STARTUPINFO));
          si.cb = sizeof(STARTUPINFOW);
          si.wShowWindow = 1; // show
          if(!CreateProcessW(L"C:\\Program Files\\ACD Systems\\ACDSee\\6.0\\ACDSee6.exe",
          L"C:\\Program Files\\ACD Systems\\ACDSee\\6.0\\ACDSee6.exe",
          NULL,
          NULL,
          FALSE,
          0,
          NULL,
          NULL,
          &si,
          &pi))
          {
          ASSERT(FALSE);// failure
          }

          // success

          ok , the above code seems ok, but the problem is i pass the create process sucessfully, and i can't see any ACDSEE window open (nor i can't see the process in the task manager).... if i use this substitue code:

          ShellExecuteW(NULL,
          L"open",
          L"C:\\Program Files\\ACD Systems\\ACDSee\\6.0\\ACDSee6.exe",
          NULL,
          NULL,
          SW_SHOWNORMAL);

          it is working ok and ACDSEE is opened. i can't use ShellExecute because i need some process information which PROCESS_INFORMATION structure holds.... can any1 help? thanks in advanced Yaron Ask not what your application can do for you, Ask what you can do for your application

          G Offline
          G Offline
          Gavin Taylor
          wrote on last edited by
          #4

          I'm not sure if this is what the problem is as everything else looks ok, according at MSDN if your using using the si.wShowWindow property you need to set si.dwFlags to STARTF_USESHOWWINDOW else it'll just ignore it. Out of interest have you tried changing it to launch Word or something to check the code is working ok? Gavin Taylor w: http://www.gavspace.com

          Y 1 Reply Last reply
          0
          • G Gavin Taylor

            I'm not sure if this is what the problem is as everything else looks ok, according at MSDN if your using using the si.wShowWindow property you need to set si.dwFlags to STARTF_USESHOWWINDOW else it'll just ignore it. Out of interest have you tried changing it to launch Word or something to check the code is working ok? Gavin Taylor w: http://www.gavspace.com

            Y Offline
            Y Offline
            YaronNir
            wrote on last edited by
            #5

            also tried it (the STARTF_USESHOWWINDOW ) and still not working... I tried creating process of notepad.exe and it works 100%!!! i think the problem is the environment while i create ACDSEE 6 process...because it works fine with ACDSEE 3....not sure why though.... any thought? thanks again Yaron Ask not what your application can do for you, Ask what you can do for your application

            1 Reply Last reply
            0
            • Y YaronNir

              Hi all, I want to run ACDSee from create process this is the code i use:

              STARTUPINFOW si;
              PROCESS_INFORMATION pi;
              ZeroMemory(&pi,sizeof(PROCESS_INFORMATION));
              ZeroMemory(&si,sizeof(STARTUPINFO));
              si.cb = sizeof(STARTUPINFOW);
              si.wShowWindow = 1; // show
              if(!CreateProcessW(L"C:\\Program Files\\ACD Systems\\ACDSee\\6.0\\ACDSee6.exe",
              L"C:\\Program Files\\ACD Systems\\ACDSee\\6.0\\ACDSee6.exe",
              NULL,
              NULL,
              FALSE,
              0,
              NULL,
              NULL,
              &si,
              &pi))
              {
              ASSERT(FALSE);// failure
              }

              // success

              ok , the above code seems ok, but the problem is i pass the create process sucessfully, and i can't see any ACDSEE window open (nor i can't see the process in the task manager).... if i use this substitue code:

              ShellExecuteW(NULL,
              L"open",
              L"C:\\Program Files\\ACD Systems\\ACDSee\\6.0\\ACDSee6.exe",
              NULL,
              NULL,
              SW_SHOWNORMAL);

              it is working ok and ACDSEE is opened. i can't use ShellExecute because i need some process information which PROCESS_INFORMATION structure holds.... can any1 help? thanks in advanced Yaron Ask not what your application can do for you, Ask what you can do for your application

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

              What does GetLastError() tell you?


              "Take only what you need and leave the land as you found it." - Native American Proverb

              Y 1 Reply Last reply
              0
              • Y YaronNir

                Hi all, I want to run ACDSee from create process this is the code i use:

                STARTUPINFOW si;
                PROCESS_INFORMATION pi;
                ZeroMemory(&pi,sizeof(PROCESS_INFORMATION));
                ZeroMemory(&si,sizeof(STARTUPINFO));
                si.cb = sizeof(STARTUPINFOW);
                si.wShowWindow = 1; // show
                if(!CreateProcessW(L"C:\\Program Files\\ACD Systems\\ACDSee\\6.0\\ACDSee6.exe",
                L"C:\\Program Files\\ACD Systems\\ACDSee\\6.0\\ACDSee6.exe",
                NULL,
                NULL,
                FALSE,
                0,
                NULL,
                NULL,
                &si,
                &pi))
                {
                ASSERT(FALSE);// failure
                }

                // success

                ok , the above code seems ok, but the problem is i pass the create process sucessfully, and i can't see any ACDSEE window open (nor i can't see the process in the task manager).... if i use this substitue code:

                ShellExecuteW(NULL,
                L"open",
                L"C:\\Program Files\\ACD Systems\\ACDSee\\6.0\\ACDSee6.exe",
                NULL,
                NULL,
                SW_SHOWNORMAL);

                it is working ok and ACDSEE is opened. i can't use ShellExecute because i need some process information which PROCESS_INFORMATION structure holds.... can any1 help? thanks in advanced Yaron Ask not what your application can do for you, Ask what you can do for your application

                D Offline
                D Offline
                Daniel Lohmann
                wrote on last edited by
                #7

                Two potential reasons: 1) the lpCommandLine parameter of CreateProcessW() is the white-space delimited list of arguments passed as argv to the new process. If ACDSee expects to find the path to its own executable in argv[0] the above would fail, as your path contains whitespaces. Basically the result of the above would be: argv[0]="C:\Program", argv[1]="Files\ACD", argv[2]="Systems\ACDSee\6.0}ACDSee6.exe" You should quote the string, e.g. pass it as: L"\"C:\\Program Files\\ACD Systems\\ACDSee\\6.0\\ACDSee6.exe\"" 2) The UNICODE-Version of CreateProcess() may fail on NT/2k/XP if the parameter passed as lpCommandLine points to a constant string. This is explicitly mentioned in MSDN. Note that the type is LPWSTR, not LPCWSTR. Maybe you should copy your string to a modifiable buffer and pass this buffer to CreateProcessW(): I usually pass NULL for the lpApplication parameter and only use lpCommandLine. Of course, you have to make sure that a path containing white-spaces is quoted in this case (as described above). ShellExecute() is intended to be more "user friendly", that is it applies some heuristics to resolve pathes containing white spaces and does other "magic stuff". Hope that helps -- Daniel Lohmann http://www.losoft.de (Hey, this page is worth looking! You can find some free and handy NT tools there :-D )

                Y 1 Reply Last reply
                0
                • D Daniel Lohmann

                  Two potential reasons: 1) the lpCommandLine parameter of CreateProcessW() is the white-space delimited list of arguments passed as argv to the new process. If ACDSee expects to find the path to its own executable in argv[0] the above would fail, as your path contains whitespaces. Basically the result of the above would be: argv[0]="C:\Program", argv[1]="Files\ACD", argv[2]="Systems\ACDSee\6.0}ACDSee6.exe" You should quote the string, e.g. pass it as: L"\"C:\\Program Files\\ACD Systems\\ACDSee\\6.0\\ACDSee6.exe\"" 2) The UNICODE-Version of CreateProcess() may fail on NT/2k/XP if the parameter passed as lpCommandLine points to a constant string. This is explicitly mentioned in MSDN. Note that the type is LPWSTR, not LPCWSTR. Maybe you should copy your string to a modifiable buffer and pass this buffer to CreateProcessW(): I usually pass NULL for the lpApplication parameter and only use lpCommandLine. Of course, you have to make sure that a path containing white-spaces is quoted in this case (as described above). ShellExecute() is intended to be more "user friendly", that is it applies some heuristics to resolve pathes containing white spaces and does other "magic stuff". Hope that helps -- Daniel Lohmann http://www.losoft.de (Hey, this page is worth looking! You can find some free and handy NT tools there :-D )

                  Y Offline
                  Y Offline
                  YaronNir
                  wrote on last edited by
                  #8

                  Thanks for all the replies! i've managed...the problem was that when creating acdsee6 process, you need to set up the acdsee environment (because it loads some dll that are located else where) so you can get the environment out of the registry and then use the 'SetEnvironmentVariable' method this works 100%.... to discover that, i needed to hook the ShellExecute method, and learned that it calls CreateProcess behind the scenes, with the necessary paramters that one of them was the environment looking at the memroy of that variable, i've seen the acdsee directory reference (the one that the dll reside)... so mission completed :) thanks again Yaron Ask not what your application can do for you, Ask what you can do for your application

                  1 Reply Last reply
                  0
                  • D David Crow

                    What does GetLastError() tell you?


                    "Take only what you need and leave the land as you found it." - Native American Proverb

                    Y Offline
                    Y Offline
                    YaronNir
                    wrote on last edited by
                    #9

                    i've managed! please see my other reply that summarize it all thank you my friend Yaron Ask not what your application can do for you, Ask what you can do for your application

                    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