Announcement

Collapse
No announcement yet.

How to determine the path my .EXE is in???

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to determine the path my .EXE is in???

    Often users create a shortcut to run my program and for various valid reasons they will set a "start in" path of their own making. I also do not know where my program file (the .EXE file) resides. I would like to create a file in that folder but I don't know how to determine where the user installed it. Aside from registry crap, is there an environment variable or something in PB I can use to get the path that the .EXE is in? CURDIR is not what I am after.

    Thanks!

  • #2
    If you are using PB9 then check out the "EXE" statement in the Help file. If you want to use the WinAPI then do a search on these forums for GetModuleFileName.
    Paul Squires
    FireFly Visual Designer (for PowerBASIC Windows 10+)
    Version 3 now available.
    http://www.planetsquires.com

    Comment


    • #3
      many thanks Paul!

      Comment


      • #4
        Originally posted by Jim McLachlan View Post
        I would like to create a file in that folder but ...
        But be aware that this will cause problems if your user runs VISTA

        Hans

        Comment


        • #5
          Move That INI File! and Get That Ini File Name!

          You can put your data files in the same folder as the INI file, or make a subfolder for data.
          Michael Mattias
          Tal Systems (retired)
          Port Washington WI USA
          [email protected]
          http://www.talsystems.com

          Comment


          • #6
            Try this Instance Parent on post #18 I posted code that will show you where your program is running from

            Engineer's Motto: If it aint broke take it apart and fix it

            "If at 1st you don't succeed... call it version 1.0"

            "Half of Programming is coding"....."The other 90% is DEBUGGING"

            "Document my code????" .... "WHYYY??? do you think they call it CODE? "

            Comment


            • #7
              Locating Data and Configuration Files
              Bernard Ertl
              InterPlan Systems

              Comment


              • #8
                I found this code below on poffs:

                Code:
                FUNCTION AppFullPath() AS STRING         'get the path of this exe file
                    LOCAL appFilename  AS ASCIIZ * 255
                    LOCAL PathPos      AS LONG
                    GetModuleFileName GetModuleHandle(""), appFilename, 255
                    PathPos = INSTR(-1,appFilename,"\")   'find the LAST "\" and hack out the -1 in instr func
                    FUNCTION = LEFT$(appFilename,PathPos)
                END FUNCTION
                Use: exe_path$ = AppFullPath

                K.

                Comment


                • #9
                  Originally posted by Hans-Dieter Veit View Post
                  But be aware that this will cause problems if your user runs VISTA
                  This has been a problem since W2K at least, because users running under a restricted account (recommended for all non-administrative tasks) don't have rights to create files in %PROGRAM FILES%.

                  It was just that everybody and his dog did run their machines with an account having administrative privileges ...

                  Comment


                  • #10
                    PBCC 5+, PBWIN 9+
                    Code:
                    programpath$= EXE.PATH$
                    Caution until the doc improvement suggestion I sent in yesterday appears in the help file: "EXE.Path$ is returned with the trailing backslash."

                    (I sent in suggestion because yesterday I had to guess if it was supplied or not. I guessed wrong).
                    Michael Mattias
                    Tal Systems (retired)
                    Port Washington WI USA
                    [email protected]
                    http://www.talsystems.com

                    Comment

                    Working...
                    X