Link to home
Start Free TrialLog in
Avatar of philkryder
philkryder

asked on

?I would like a VBS or other program that I can call that will give me the complete PATH and FILE name of the CALLING program?

I would like to know where a program is located.

Therefore,
I would like a program that I can call that will tell me the complete windows path and filename of the calling program.

For example.
Let's suppose that I have a program named MYprog.exe
and it is located in:
c:\Program Files\MyApplication\CurrentProduction

Let's suppose the new program that you supply would be named:
ReturnsCallersLocation.VBS

Then,
I would like to be able to have MYprog.exe call ReturnsCallersLocation.vbs,
  which would return a string containing:
"c:\Program Files\MyApplication\CurrentProduction\MYprog.exe"

I "think"
VBS script would be easiest for me to use.
But, other languages could be acceptable.

Thanks
Phil





Avatar of Kyle Abrahams, PMP
Kyle Abrahams, PMP
Flag of United States of America image

Not sure if you can do that direct . . . but a work around would be to force your script to have a parameter that accepts the path & program name.  If it's not there error out of your script.
I have a script that will work using AutoIT, on one condition;

Within MYprog.exe, are you able to call this script with a switch that is MYprog.exe? For example, the script below (which we'll call ReturnsCallersLocation.exe) would need to be run like this:

ReturnsCallersLocation.exe MYprog.exe
_ProcessGetLocation($CmdLineRaw)

Func _ProcessGetLocation($iPIDa)
    $iPID=ProcessExists($iPIDa)
	Local $aProc = DllCall('kernel32.dll', 'hwnd', 'OpenProcess', 'int', BitOR(0x0400, 0x0010), 'int', 0, 'int', $iPID)
    If $aProc[0] = 0 Then Return SetError(1, 0, '')
    Local $vStruct = DllStructCreate('int[1024]')
    DllCall('psapi.dll', 'int', 'EnumProcessModules', 'hwnd', $aProc[0], 'ptr', DllStructGetPtr($vStruct), 'int', DllStructGetSize($vStruct), 'int_ptr', 0)
    Local $aReturn = DllCall('psapi.dll', 'int', 'GetModuleFileNameEx', 'hwnd', $aProc[0], 'int', DllStructGetData($vStruct, 1), 'str', '', 'int', 2048)
    If StringLen($aReturn[3]) = 0 Then Return SetError(2, 0, '')
    Return $aReturn[3]
EndFunc

Open in new window

Is this to troubleshoot a program to make sure the correct one is the one running? Or that it is running the correct script?

As I read your question, you are asking an external application to determine something for you that is available in the application itself.
 Every dos/windows programming language I have used has a function in it to determine the path of the program itself. ie If you are creating a myprog.exe there are calls from whatever programing language you are using to determine what you ask.

If you are trying to determine in the script if the correct program has called it then TheGorby's solution would work, but if you are trying to determine for myprog.exe where it is running from there are far simpler ways available to run inside the myprog.exe itself.

Avatar of philkryder
philkryder

ASKER


I am using an automation tool that does NOT have a user interface provitding the ability to compute it's own location.

thus, I would like to have a program that I can call that will determine the location of the calling program.



I am not sure what auto.IT is

I don't know how I would instantiate the switch equal to the calling program.
Phil
ASKER CERTIFIED SOLUTION
Avatar of TheGorby
TheGorby
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial