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. Executable not opening using ShellExecute()

Executable not opening using ShellExecute()

Scheduled Pinned Locked Moved C / C++ / MFC
question
5 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.
  • C Offline
    C Offline
    CNewbie
    wrote on last edited by
    #1

    This is a continuation from my earlier thread so all could respond. When I try to open an executable from my program using the following line it opens the executable then immdiatley closes it.: ShellExecute(NULL,_T("open"),_T("cd1\\CBTNuggetPlayer.exe"),NULL,NULL,SW_SHOW); The executable is a GUI and it opens fine if I go to the directory and double click on it, but it wont open the window when I try to open it from my program. As I said earlier, I am using a relative path since my program will be at the root of a CD and the executable will be 1 to 2 layers down as it is here. Anyone know why? thanks

    T N 2 Replies Last reply
    0
    • C CNewbie

      This is a continuation from my earlier thread so all could respond. When I try to open an executable from my program using the following line it opens the executable then immdiatley closes it.: ShellExecute(NULL,_T("open"),_T("cd1\\CBTNuggetPlayer.exe"),NULL,NULL,SW_SHOW); The executable is a GUI and it opens fine if I go to the directory and double click on it, but it wont open the window when I try to open it from my program. As I said earlier, I am using a relative path since my program will be at the root of a CD and the executable will be 1 to 2 layers down as it is here. Anyone know why? thanks

      T Offline
      T Offline
      Taka Muraoka
      wrote on last edited by
      #2

      Using relative paths is *always* asking for trouble. The fact that ShellExecute() doesn't appear to be working indicates that it's not finding the EXE :-) How do you know somebody won't copy your CD to a hard disk and run it from there? How do you know what the *current directory* will be when your main program is run. ShellExecute() starts from the current directory, not where the main program lives. I always figure out where my main program is using GetModuleFileName() and generate absolute paths relative to that.


      The two most common elements in the universe are Hydrogen and stupidity. - Harlan Ellison Awasu 2.2 [^]: A free RSS/Atom feed reader with support for Code Project.

      C 1 Reply Last reply
      0
      • T Taka Muraoka

        Using relative paths is *always* asking for trouble. The fact that ShellExecute() doesn't appear to be working indicates that it's not finding the EXE :-) How do you know somebody won't copy your CD to a hard disk and run it from there? How do you know what the *current directory* will be when your main program is run. ShellExecute() starts from the current directory, not where the main program lives. I always figure out where my main program is using GetModuleFileName() and generate absolute paths relative to that.


        The two most common elements in the universe are Hydrogen and stupidity. - Harlan Ellison Awasu 2.2 [^]: A free RSS/Atom feed reader with support for Code Project.

        C Offline
        C Offline
        CNewbie
        wrote on last edited by
        #3

        Yes, I do understand that it starts from the current directory, that is why I start the relative path from the my program will be which is one directory up the tree which would be cd1/CBTNuggetsPlayer.exething I needed to know is the proper format for a relative path so i know I am doing it right.

        1 Reply Last reply
        0
        • C CNewbie

          This is a continuation from my earlier thread so all could respond. When I try to open an executable from my program using the following line it opens the executable then immdiatley closes it.: ShellExecute(NULL,_T("open"),_T("cd1\\CBTNuggetPlayer.exe"),NULL,NULL,SW_SHOW); The executable is a GUI and it opens fine if I go to the directory and double click on it, but it wont open the window when I try to open it from my program. As I said earlier, I am using a relative path since my program will be at the root of a CD and the executable will be 1 to 2 layers down as it is here. Anyone know why? thanks

          N Offline
          N Offline
          Nibu babu thomas
          wrote on last edited by
          #4

          CNewbie wrote:

          ShellExecute(NULL,_T("open"),_T("cd1\\CBTNuggetPlayer.exe"),NULL,NULL,SW_SHOW);

          ShellExecute(NULL,_T("open"),_T("**.\\**cd1\\CBTNuggetPlayer.exe"),NULL,NULL,SW_SHOW);


          Nibu thomas Software Developer

          C 1 Reply Last reply
          0
          • N Nibu babu thomas

            CNewbie wrote:

            ShellExecute(NULL,_T("open"),_T("cd1\\CBTNuggetPlayer.exe"),NULL,NULL,SW_SHOW);

            ShellExecute(NULL,_T("open"),_T("**.\\**cd1\\CBTNuggetPlayer.exe"),NULL,NULL,SW_SHOW);


            Nibu thomas Software Developer

            C Offline
            C Offline
            CNewbie
            wrote on last edited by
            #5

            Just updating, I tried this and it still will not open the window, I just see the executable open in task manager then 1 second later it closes and I never see any window open: ShellExecute(NULL,_T("open"),_T(".\\cd1\\CBTNuggetPlayer.exe"),NULL,NULL,SW_SHOW); not sure what else to try. I've gone through the flags to no avail.

            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