Silverfrost Forums

Welcome to our forums

How to find the name of currently running EXE ?

11 Sep 2025 10:36 (Edited: 11 Sep 2025 11:09) #32334

What function can supply the name of currently running program to this program?

I often run several instances of EXE at the same time and eventually become totally lost to find what is what. I may close some wrong program as a result. But if I will give EXE different names and display these names on running Clearwin window I will always know what is what

I know Clearwin command which supplies the path of the running code and display this path on top of each window, but this command does not supply the name of EXE

Opposite situation is with SDBG: it displays on the top the name of my EXE file which it is running but does not supply the path where is this EXE from. Would be good if it display the whole path too. For example now are running 5 programs under SDBG, each took hours to run and it is not easy to find what program is running under this or that open SDBG. Will also note, that the Command Prompt black window which SDBG opens at start has all the right path and the name of SDBG itself (showing that it is in the main FTN95 compiler directory). But what needed is that another SDBG window (where the debug actually happens) had display not just my code EXE name but the whole path with EXE name

11 Sep 2025 11:08 #32335

Dan, Does this help?

program get_progname
  use mswin
  implicit none

  integer(7) :: hModule
  integer    :: nChars
  character(len=260) :: buffer

  hModule = 0   ! 0 = current process
  nChars = GetModuleFileName(hModule, buffer, len(buffer))

  if (nChars > 0) then
     print *, 'Running program is: ', trim(buffer(:nChars))
  else
     print *, 'Could not get program name.'
  end if
end program
11 Sep 2025 11:12 #32336

Thanks you Ken, that exactly what was needed

23 Sep 2025 1:25 #32354

Similarly, one can use:

cmprognm@()
27 Sep 2025 5:08 #32362

Thanks Bill.

I tried it but unfortunately it does not work

AI gave me test program how to use it and it also does not work:

PROGRAM GetProgramName
  IMPLICIT NONE
  CHARACTER(LEN=256) :: cmprognm@
  CHARACTER(LEN=256) :: program_name

    program_name = cmprognm@()
  
  WRITE(*,*) 'The name of this program is: ', TRIM(program_name)

END PROGRAM GetProgramName
27 Sep 2025 5:56 #32363

It works for me. What goes wrong?

27 Sep 2025 8:40 #32364

This gives just the empty output. I am using WINE Windows emulation in Linux though. May be this is the reason. But so far I had very little and just the minor differences with true Windows, so I even do not remember what they were, this is probably the first one. The code Ken provided works OK.

Please login to reply.