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. ShellExecute swallowing empty parameter

ShellExecute swallowing empty parameter

Scheduled Pinned Locked Moved C / C++ / MFC
csharpc++saleshelptutorial
7 Posts 2 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
    mav northwind
    wrote on last edited by
    #1

    Hi guys! I got a really strange behaviour on one customer machine I really cannot figure out - perhaps someone can help... A C++ plugin DLL of mine loaded into a third party application is calling one of my .NET applications using ShellExecute. Several arguments are passed along in this call, the last one being an empty string. Basically the call looks like this:

    ShellExecute(AfxGetMainWnd()->GetSafeHwnd(), NULL, "C:\\Program Files\\MyApp\\MyApp.exe", "/arg1 /arg2 /arg3 \"argument3\" /arg4 \"\"", "C:\\Program Files\\MyApp", SW_SHOW);

    /arg1 and /arg2 are simple flags for my .NET app, whereas /arg3 and /arg4 require an additional parameter. The parameter for /arg4 is supposed to be an empty string for this call. The exact same version of this DLL works fine on many other machines, but on this particular one my .NET application won't start because it claims that the parameter for /arg4 is missing! I'm logging the arguments my application is called with and can see that the last parameter is missing, although the empty string is hard-coded inside the DLL and it works on every other machine I've come across so far. What can be the reason for ShellExecute silently swallowing the last parameter? Thanks in advance for every idea about how to proceed here...

    Regards, mav -- Black holes are the places where God divided by 0...

    D 1 Reply Last reply
    0
    • M mav northwind

      Hi guys! I got a really strange behaviour on one customer machine I really cannot figure out - perhaps someone can help... A C++ plugin DLL of mine loaded into a third party application is calling one of my .NET applications using ShellExecute. Several arguments are passed along in this call, the last one being an empty string. Basically the call looks like this:

      ShellExecute(AfxGetMainWnd()->GetSafeHwnd(), NULL, "C:\\Program Files\\MyApp\\MyApp.exe", "/arg1 /arg2 /arg3 \"argument3\" /arg4 \"\"", "C:\\Program Files\\MyApp", SW_SHOW);

      /arg1 and /arg2 are simple flags for my .NET app, whereas /arg3 and /arg4 require an additional parameter. The parameter for /arg4 is supposed to be an empty string for this call. The exact same version of this DLL works fine on many other machines, but on this particular one my .NET application won't start because it claims that the parameter for /arg4 is missing! I'm logging the arguments my application is called with and can see that the last parameter is missing, although the empty string is hard-coded inside the DLL and it works on every other machine I've come across so far. What can be the reason for ShellExecute silently swallowing the last parameter? Thanks in advance for every idea about how to proceed here...

      Regards, mav -- Black holes are the places where God divided by 0...

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

      mav.northwind wrote:

      What can be the reason for ShellExecute silently swallowing the last parameter?

      If it's empty, what's to swallow?

      "Love people and use things, not love things and use people." - Unknown

      "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

      M 1 Reply Last reply
      0
      • D David Crow

        mav.northwind wrote:

        What can be the reason for ShellExecute silently swallowing the last parameter?

        If it's empty, what's to swallow?

        "Love people and use things, not love things and use people." - Unknown

        "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

        M Offline
        M Offline
        mav northwind
        wrote on last edited by
        #3

        That's the minute, but essential difference between passing no argument or an empty string as argument...

        Regards, mav -- Black holes are the places where God divided by 0...

        D 1 Reply Last reply
        0
        • M mav northwind

          That's the minute, but essential difference between passing no argument or an empty string as argument...

          Regards, mav -- Black holes are the places where God divided by 0...

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

          But can the OS/shell differentiate between the two? For example, how would you execute that program from a command prompt?

          "Love people and use things, not love things and use people." - Unknown

          "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

          M 1 Reply Last reply
          0
          • D David Crow

            But can the OS/shell differentiate between the two? For example, how would you execute that program from a command prompt?

            "Love people and use things, not love things and use people." - Unknown

            "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

            M Offline
            M Offline
            mav northwind
            wrote on last edited by
            #5

            app.exe /one /two

            vs.

            app.exe /one /two ""

            You can easily try it out. In the first case, argc is 2, in the second one it's 3. It's very similar to what you have to do when one of the parameters contains white spaces, i.e. enclose the parameter in double quotes so that the shell can tell where one parameter ends and the next one begins.

            Regards, mav -- Black holes are the places where God divided by 0...

            D 1 Reply Last reply
            0
            • M mav northwind

              app.exe /one /two

              vs.

              app.exe /one /two ""

              You can easily try it out. In the first case, argc is 2, in the second one it's 3. It's very similar to what you have to do when one of the parameters contains white spaces, i.e. enclose the parameter in double quotes so that the shell can tell where one parameter ends and the next one begins.

              Regards, mav -- Black holes are the places where God divided by 0...

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

              So have you tried this with CreateProcess() instead?

              "Love people and use things, not love things and use people." - Unknown

              "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

              M 1 Reply Last reply
              0
              • D David Crow

                So have you tried this with CreateProcess() instead?

                "Love people and use things, not love things and use people." - Unknown

                "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                M Offline
                M Offline
                mav northwind
                wrote on last edited by
                #7

                No, I haven't tried anything that involves changing the DLL yet. It's rather complicated - I cannot just modify the DLL and redeploy. But perhaps we found something: The administrator at the customer's site found some malware during an AV scan and will now reset the machine to their standard image. So chances are some badly written malware was not passing along all the parameters in this case. I've just got to keep my fingers crossed that it'll work again afterwards.

                Regards, mav -- Black holes are the places where God divided by 0...

                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