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. How to find that an application is executed from command prompt or by double clicking the application ?

How to find that an application is executed from command prompt or by double clicking the application ?

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

    I have an application and it can be executed both through the command prompt and by double clicking the application file (i.e. App.exe). :sigh: The problem is that when the application is double clicked the GetCurrentDirectory() method gives a different path and when it is executed through command-prompt it gives a different path and so i can not use the path retrieved, so if i can identify somehow the way it is invoked, i might make a fix for it. Please HELP...!!:confused: Thanks in advance. ;)

    Z D M 3 Replies Last reply
    0
    • D Dharmendra Bhargava

      I have an application and it can be executed both through the command prompt and by double clicking the application file (i.e. App.exe). :sigh: The problem is that when the application is double clicked the GetCurrentDirectory() method gives a different path and when it is executed through command-prompt it gives a different path and so i can not use the path retrieved, so if i can identify somehow the way it is invoked, i might make a fix for it. Please HELP...!!:confused: Thanks in advance. ;)

      Z Offline
      Z Offline
      zhu_lin
      wrote on last edited by
      #2

      GetModuleFileName API

      it's my pleasure to make friend with you.

      D 1 Reply Last reply
      0
      • D Dharmendra Bhargava

        I have an application and it can be executed both through the command prompt and by double clicking the application file (i.e. App.exe). :sigh: The problem is that when the application is double clicked the GetCurrentDirectory() method gives a different path and when it is executed through command-prompt it gives a different path and so i can not use the path retrieved, so if i can identify somehow the way it is invoked, i might make a fix for it. Please HELP...!!:confused: Thanks in advance. ;)

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

        Dharmendra Bhargava wrote:

        I have an application and it can be executed both through the command prompt and by double clicking the application file (i.e. App.exe)...so if i can identify somehow the way it is invoked, i might make a fix for it.

        Add some command-line argument to the one that is double-clicked (in Explorer).

        "Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown

        "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

        1 Reply Last reply
        0
        • D Dharmendra Bhargava

          I have an application and it can be executed both through the command prompt and by double clicking the application file (i.e. App.exe). :sigh: The problem is that when the application is double clicked the GetCurrentDirectory() method gives a different path and when it is executed through command-prompt it gives a different path and so i can not use the path retrieved, so if i can identify somehow the way it is invoked, i might make a fix for it. Please HELP...!!:confused: Thanks in advance. ;)

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

          Which directory do you want? The one where your executable resides or the one from where you launch it (which could be a different directory)? In case you need the directory where the executable is located you can use GetModuleFileName() as already suggested.

          1 Reply Last reply
          0
          • Z zhu_lin

            GetModuleFileName API

            it's my pleasure to make friend with you.

            D Offline
            D Offline
            Dharmendra Bhargava
            wrote on last edited by
            #5

            Thanks "zhu_lin" for the quick reply, it works fine now. :-D

            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