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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Using command line parameters with ShellExecute() ?

Using command line parameters with ShellExecute() ?

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
8 Posts 3 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.
  • A Offline
    A Offline
    Atom
    wrote on last edited by
    #1

    Hi, I am trying to call ShellExecute() to run an .exe that takes 1 or more file paths as command line parameter(s). Although when I format a string like: ""C:\\file1.txt" "C:\\file2.txt" "C:\\file3.txt"" as the lpParameters param I always get an SE_ERR_ACCESSDENIED error. Am I using the correct command line formatting, as if I pass a "" (NULL string) as lpParameters the function runs the exe OK. Many Thanks.

    T 1 Reply Last reply
    0
    • A Atom

      Hi, I am trying to call ShellExecute() to run an .exe that takes 1 or more file paths as command line parameter(s). Although when I format a string like: ""C:\\file1.txt" "C:\\file2.txt" "C:\\file3.txt"" as the lpParameters param I always get an SE_ERR_ACCESSDENIED error. Am I using the correct command line formatting, as if I pass a "" (NULL string) as lpParameters the function runs the exe OK. Many Thanks.

      T Offline
      T Offline
      toxcct
      wrote on last edited by
      #2

      use the \" character to insert a double quote character in your string


      [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

      A 1 Reply Last reply
      0
      • T toxcct

        use the \" character to insert a double quote character in your string


        [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

        A Offline
        A Offline
        Atom
        wrote on last edited by
        #3

        This is what i've done already, The string I've included in the example is how it appears in memory(NOT in source code). I just can't work this out as when I double click a file that is associated with the exe in explorer the command line reads with quotes around that file name EXACTLY as I have in the source code.

        M 1 Reply Last reply
        0
        • A Atom

          This is what i've done already, The string I've included in the example is how it appears in memory(NOT in source code). I just can't work this out as when I double click a file that is associated with the exe in explorer the command line reads with quotes around that file name EXACTLY as I have in the source code.

          M Offline
          M Offline
          Michael Dunn
          wrote on last edited by
          #4

          Atom wrote:

          The string I've included in the example is how it appears in memory(NOT in source code).

          Then the backslashes are the problem. You only use one backslash in file paths.

          --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ Ford, what's this fish doing in my ear?

          A 1 Reply Last reply
          0
          • M Michael Dunn

            Atom wrote:

            The string I've included in the example is how it appears in memory(NOT in source code).

            Then the backslashes are the problem. You only use one backslash in file paths.

            --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ Ford, what's this fish doing in my ear?

            A Offline
            A Offline
            Atom
            wrote on last edited by
            #5

            Hi, Thanks, solved the problems with the backslashes, now I can shellexecute() with a command line containing multiple file paths. The problem I am having now is that when I test the command line string with a string of length 1951 it works fine, but if I add one more file path to this string which takes the length to 1983 the function fails. So presumably the command line string has a max length between 1951 & 1983. I will test this further, maybe shellexecuteEX() is the way to go. Many thanks for your help.

            T 1 Reply Last reply
            0
            • A Atom

              Hi, Thanks, solved the problems with the backslashes, now I can shellexecute() with a command line containing multiple file paths. The problem I am having now is that when I test the command line string with a string of length 1951 it works fine, but if I add one more file path to this string which takes the length to 1983 the function fails. So presumably the command line string has a max length between 1951 & 1983. I will test this further, maybe shellexecuteEX() is the way to go. Many thanks for your help.

              T Offline
              T Offline
              toxcct
              wrote on last edited by
              #6

              how do you know the function fails ? getting an error message ? if yes, can you share with us ? BTW, ther's nothing restricting the length of the parameter you're talking about under the 1983 characters. this is simply non sense... !


              [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

              A 1 Reply Last reply
              0
              • T toxcct

                how do you know the function fails ? getting an error message ? if yes, can you share with us ? BTW, ther's nothing restricting the length of the parameter you're talking about under the 1983 characters. this is simply non sense... !


                [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

                A Offline
                A Offline
                Atom
                wrote on last edited by
                #7

                The error that I was getting was, SE_ERR_ACCESSDENIED The length limit is NOT nonsense. ! The following link describes the length restrictions on the parameter I am talking about: ShellExecute parameter limit. I guess my 1983 char length string has the .exe file path name appended to it taking the to total string length to > INTERNET_MAX_URL_LENGTH. Which is why I was getting the error. I've solved the problem now, using an intermediate file to get around any command line length limits. Thanks for the advice.

                T 1 Reply Last reply
                0
                • A Atom

                  The error that I was getting was, SE_ERR_ACCESSDENIED The length limit is NOT nonsense. ! The following link describes the length restrictions on the parameter I am talking about: ShellExecute parameter limit. I guess my 1983 char length string has the .exe file path name appended to it taking the to total string length to > INTERNET_MAX_URL_LENGTH. Which is why I was getting the error. I've solved the problem now, using an intermediate file to get around any command line length limits. Thanks for the advice.

                  T Offline
                  T Offline
                  toxcct
                  wrote on last edited by
                  #8

                  yes, and quoting it says : If you are using the ShellExecute/Ex function, then you become subject to the INTERNET_MAX_URL_LENGTH (around 2048) command line length limit imposed by the ShellExecute/Ex functions. (If you are running on Windows 95, then the limit is only MAX_PATH.) so...


                  [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

                  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