venerdì 19 ottobre 2018

I want to know the PATH of an EXE


Never happened that you run an exe from command prompt and you are not sure from what path it's run? sometimes this make the difference. Maybe you have multiple version of an exe, in multiple path or something like that, it's not working like expected and you want to be sure the correct one is run.

If the executable is gui application this is not really an issue, you can obtain the info from the task manager adding for example the "cmd" column, but if the executable is a command line one, that start and end in milliseconds, than you are in trouble.

One clue come from the command "where.exe":

where executablename

will give you all the path where that executable can be find.
But this will not tell you from which path it is run when you digit:

executablename

from a random folder from command prompt

As I'm not aware of any other way to know the path where it is run from , I wrote a very small console application in C# that simply run the process and print the process filename:

si = new ProcessStartInfo(args);
using (Process pr = Process.Start(si))
{
  Console.WriteLine("*****************************************************");
  Console.WriteLine(pr.MainModule.FileName);
  Console.WriteLine("*****************************************************");
}

this does exactly what I need.

For example running my app from a random folder against "dism.exe" I see this:

C:\it>exepath dism
*****************************************************
C:\Windows\System32\Dism.exe
*****************************************************

Nessun commento:

Posta un commento