Announcement

Collapse
No announcement yet.

Running program name

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

  • Running program name

    Using Win XP and PB 3.5 for Dos
    Junk.exe is running just fine.
    I would like to: PRINT z$ 'z$ contains 'Junk.exe'

    Can a running program determine it’s own name?
    I know the answer is 'yes', but don't know what the code would be.

    Push me in the right direction, please.
    Thanks again for all the great assistance in the past.

    Jack


    ------------------

  • #2
    Code:
    ' file:exename.bas. creates a UNIT which can be linked which has the
    ' FUNCTION ExeName$. Exename$ returns the fully qualified DOS file name of
    ' the current program. See BasicPro Vol. 3 No. 1 (Feb/Mar 1993) page
    ' 49-50 for the code listing there.
    ' HISTORY ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    ' 02.16.93 coded (pb2.10)
    ' 01.05.94 created pb3.0c UNIT file
    ' 12.27.95 created PB 3.2 unit file RENAMED EXENAMEU
    ' 12.04.00 updated to PB 3.5
    ' ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    $STACK 2048
    ' Valid values for $STACK are 1536 thru 32766 (decimal)
    $OPTION AUTODIM-, CNTLBREAK+
    $LIB ALL OFF
    $COMPILE UNIT
    DEFINT A - Z			' Variables are Integer unless overridden
    
    FUNCTION ExeFileName$ LOCAL PUBLIC
    
     REG 1, &h6200			' set AX = &6200 function &62
     CALL INTERRUPT &h21		' call DOS: returns....
     EnvSeg= REG(2)			' environment segment in bx
     DEF SEG=EnvSeg
     EnvPtr& = CLNG(PEEKI(44))      ' bytes 44,45 of envseg
     DEF SEG=EnvPtr&   		' set segment here
     Byte = 0
     DO     			' search for two zero bytes in a row
      IF Peek(Byte) = 0 THEN
        IF PEEK(Byte + 1) = 0 THEN
         INCR Byte, 2
         EXIT LOOP
        END IF
      END IF
      INCR Byte,1
     LOOP
    
     IF PEEK(byte)=1 THEN		' if next byte is 1, then the program
      INCR Byte,2			' program name follows.
      Temp$=STRING$(128,0)          ' set up a buffer
      Ptr = 0
      DO
       IF PEEK(Byte) = 0 THEN	' the name is ASCII-Z terminated (CHR$(0))
        EXIT LOOP                   ' if it ain't terminated, read it in
       ELSE                         ' a byte at a time.
        INCR Ptr,1
        MID$(temp$,ptr,1)=CHR$(PEEK(Byte))
        INCR Byte
       END IF
      LOOP
      ExeFileName$=LEFT$(Temp$,ptr)	' strip trailing chr$(0)
     ELSE				' error: return the null string
      ExeFileName$= ""
     END IF
     DEF SEG			' restore default data segment
    END FUNCTION			' ExeFileName$
    Michael Mattias
    Tal Systems Inc. (retired)
    Racine WI USA
    [email protected]
    http://www.talsystems.com

    Comment


    • #3

      Another satisfied user on this end. That is exactly what was
      needed. Works just great. Thanks for the quick response.

      'BasicPro' is something that should be known to me, but it is
      not. What is 'BasicPro'? How do I get access to 'BasicPro'?

      Thanks again, Jack

      PB Forums should live forever.



      ------------------

      Comment


      • #4
        >'BasicPro' is something that should be known to me

        Wrong.

        Old magazine, now defunct.

        Michael Mattias
        Tal Systems Inc. (retired)
        Racine WI USA
        [email protected]
        http://www.talsystems.com

        Comment

        Working...
        X