Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

QB equivalent of VB's App.Path 1

Status
Not open for further replies.

Unscruffed

Programmer
Apr 2, 2002
102
AU
Hi everyone. Got a little problem and hope you can help.
This is an example of what I'm trying to do:

I run a file called Test1.exe on my c drive.

Test1.exe then calls Test2.exe in folder c:\testapp.

So we have:
c:\Test1.exe calls c:\testapp\Test2.exe

When Test1.exe runs, CurDir$ = c:

The problem is that when Test1.exe calls Test2.exe, CurDir$ in Test2.exe also = c: and not c:\testapp. This occurs using both Shell and Run commands.

My question is, how can Test2.exe find itself? ie: same as VB's App.Path function?

It's possible to solve this by changing directory first, or sending the path in the command line, but only my own apps will know that this is required. Therefore, this solution is not an option as it will not solve the problem if Test2.exe is called from a 3rd party app, or, Test2.exe is run direct from the Dos prompt outside it's own directory.

Any help appreciated.


Be good. If you can't, don't get caught!
 
Idea (untested):
create a pif file for test2, write working directory for test2 in it.
 
Using a .Pif file doesn't work.

Test2.exe must find itself without additional files or commands.


Be good. If you can't, don't get caught!
 
Can you give a parameter to it?

SHELL "c:\dir\test2.exe c:\dir"

Then use COMMAND$

If not it seems that you would have to create a search tool to find itself. It is possible, there are a bunch of explorers at qb45.com in the misc. section
 
why do you need app.path?

unless you change the path using chgdir, it 'should' default to the applications path...

you can use "subpath\filename.txt" or "..\filenam.txt" to access files in relation to the current path.

Have Fun, Be Young... Code BASIC
-Josh
cubee101.gif


PROGRAMMER: (n) Red-eyed, mumbling mammal capable of conversing with inanimate objects.
 
After extensive searching, I found an answer this question in the following thread. Scroll half way down to the reply by Codepost.

Application Path: thread314-648413

Thanks to all who replied.

Be good. If you can't, don't get caught!
 
Thanks Unscruffed, I needed it too suddenly.

Somebody trashed the thread here at Tek-Tips, but fortunately Google had it cached yet. I searched for [tt]qbasic "application path"[/tt] and it came up.

If I had another source I'd post a link for future generations. ;-)
 
Thanks to Dilettante for pointing out that the above link is dead. The following is a copy of the post to which I was referring:



CodePost (Programmer) Sep 22, 2003
I found this aticle is in Microsoft's QB Knowledge Base. Thought you may like to have it.

- Dav

DOCUMENT:Q43560 15-JAN-1991 [B_QUICKBAS]
TITLE :Getting Full EXEC Pathname from Environment Table Using PSP


Summary:

In MS-DOS versions 3.00 and later, the full path of any executing
program is stored after the environment variables in the environment
segment that is found in the program segment prefix (PSP). This
article provides a description of how to extract the EXEC path and
gives an example of how to do this with BASIC.

This information applies to Microsoft QuickBASIC versions 4.00, 4.00b,
and 4.50, to Microsoft BASIC Compiler versions 6.00 and 6.00b for
MS-DOS, and to Microsoft BASIC Professional Development System (PDS)
versions 7.00 and 7.10.

More Information:

The segment address of the PSP for the currently executing process can
be checked with the DOS Interrupt 21 hex, function 62 hex.

The environment segment can be found in the PSP at offset 2C hex. The
environment table has an entry for each environment variable of the
format <name>=<parameter>. Each entry is terminated by a null
character [CHR$(0)] and the entire table is followed by an additional
null character. After the additional null character, there is a 2-byte
word count. Immediately after the word count, the full path of the
executing program is listed as

<drive>:<path>\<filename>.<extension>

and is also terminated by a null character.

For more information about the PSP and the environment table, see
"Advanced MS-DOS Programming, 2nd Edition" by Ray Duncan, published by
Microsoft Press (1988).

Code Example
------------

The following code example provides a function that will return the
full path of the currently executing program in DOS 3.00 and later:

Code:
'Compile and link lines:
' BC FULLPATH;
' LINK FULLPATH,,,QB.LIB;    NOTE: QBX.LIB should be used for PDS
'                                 7.00 or 7.10
'$INCLUDE: 'qb.bi'  ' NOTE: QBX.BI should be used for PDS 7.00/7.10
DECLARE FUNCTION FullPath$ ()
CONST EnvOffInPSP = &H2C

PRINT FullPath$

FUNCTION FullPath$
  DIM inregs AS RegType, OutRegs AS RegType

  inregs.ax = &H6200 'Get PSP
  CALL INTERRUPT(&H21, inregs, OutRegs)

  PSPSeg% = OutRegs.bx
  EnvironSeg& = 0
  OffSet& = 0
  tmp$ = ""

  DEF SEG = PSPSeg%
    EnvironSeg& = 256 * PEEK(EnvOffInPSP + 1) + PEEK(EnvOffInPSP)

  DEF SEG = EnvironSeg&
    WHILE (PEEK(OffSet&) <> 0 OR PEEK(OffSet& + 1) <> 0)
      OffSet& = OffSet& + 1
    WEND

    'Skip extra bytes between Env Table and Fullpath
    OffSet& = OffSet& + 4

    'Build FullPath$ (until null terminates string)
    WHILE PEEK(OffSet&) <> 0
      tmp$ = tmp$ + CHR$(PEEK(OffSet&))
      OffSet& = OffSet& + 1
    WEND
  DEF SEG

  FullPath$ = tmp$
END FUNCTION


Be good. If you can't, don't get caught!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top