It is currently Tue Mar 31, 2020 7:49 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Get ProgramFilename() info for the .exe, not .dll
PostPosted: Tue Feb 05, 2019 11:16 pm 
Offline
Enthusiast
Enthusiast

Joined: Thu May 17, 2007 8:35 pm
Posts: 113
Location: USA
If you use ProgramFilename() as a call from a .dll, the .dll and it's directory are the output.

For instance if the program is Test.exe and the .dll in it has the name display.dll, then if a function in the .dll calls ProgramFilename() from within the Test.exe, the output will show display.dll



C:\display.dll

I need it to display the name of the .exe

C:\Test.exe

Is there a call or command that shows the name and path of the running program, even if the command is called from within a .dll of that program?
Is there quick windows api hack for this? NameOfRunningProgam() !???


Top
 Profile  
Reply with quote  
 Post subject: Re: Get ProgramFilename() info for the .exe, not .dll
PostPosted: Tue Feb 05, 2019 11:23 pm 
Offline
Enthusiast
Enthusiast

Joined: Thu May 17, 2007 8:35 pm
Posts: 113
Location: USA
Another way to ask this, is there a command that can be called from within a .dll to give the path and name of the .exe that the .dll is currently being used in?


Top
 Profile  
Reply with quote  
 Post subject: Re: Get ProgramFilename() info for the .exe, not .dll
PostPosted: Wed Feb 06, 2019 4:46 pm 
Offline
Addict
Addict
User avatar

Joined: Sat Oct 09, 2010 3:47 am
Posts: 1617
Hi Mike Yurgalavage,

Windows Services & Other Stuff
- \Other_Stuff\ProcessStuff\CallingProcess\...

Run the executable and the DLL will report the calling process (path \ executable).

_________________

STATUS: Permanently Unavailable :: Downloads moved to My PureBasic Stuff
_________________


Top
 Profile  
Reply with quote  
 Post subject: Re: Get ProgramFilename() info for the .exe, not .dll
PostPosted: Thu Feb 14, 2019 12:20 am 
Offline
Enthusiast
Enthusiast

Joined: Thu May 17, 2007 8:35 pm
Posts: 113
Location: USA
JHPJHP wrote:
Hi Mike Yurgalavage,

Windows Services & Other Stuff
- \Other_Stuff\ProcessStuff\CallingProcess\...

Run the executable and the DLL will report the calling process (path \ executable).


Thanks for reply, got it sorted!

For those interested,

Code:
;-GRAB EXE NAME AND DIRECTORY
;{

OpenWindow(1,-1000,-1000,0,0,"") 

buffer.s{512}
max.q = Len(buffer)-2
window_h.q
window_name.s
process_id.q
process_h.q
This_application_name.s

OpenLibrary(1,"kernel32.dll")

K32GetModuleFileNameExW_ = GetFunction(1,"K32GetModuleFileNameExW")

window_h = WindowID(1);GetForegroundWindow_()
If window_h <> 0
  String_length.q = GetWindowText_(window_h,@buffer,max)
  window_name = PeekS(@buffer,String_length)
  GetWindowThreadProcessId_(window_h,@process_id)
    If process_id <> 0
      process_h = OpenProcess_(#PROCESS_QUERY_INFORMATION|#PROCESS_VM_READ , #False, process_id)
      If process_h <> 0
        String_length = CallFunctionFast(K32GetModuleFileNameExW_ ,process_h, 0, @buffer, max)
        This_application_name = PeekS(@buffer,String_length)
      EndIf
    EndIf
EndIf

CloseLibrary(1) 
CloseWindow(1)


best,
Mike


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye