Get Path for My .Exe

get path for my .exe


System.Reflection.Assembly.GetEntryAssembly().Location;

Getting the path of the executable file's current location

It isn't hard.

But it MIGHT depend on your target platform (which you haven't specified).

For .Net Core 1.x and .Net 5 or higher, I would use AppContext.BaseDirectory

Here are some other alternatives for various environments over the years:

6 ways to get the current directory in C#, August 17,
2010

  • AppDomain.CurrentDomain.BaseDirectory
    This is the best option all round. It will give you the base directory for class libraries,
    including those in ASP.NET applications.

  • Directory.GetCurrentDirectory()
    Note: in .NET Core this is the current best practice. The details below relate to the .NET Framework
    4.5 and below.

    This does an interop call using the winapi GetCurrentDirectory call
    inside kernel32.dll, which means the launching process’ folder will
    often be returned. Also as the MSDN documents say, it’s not guaranteed
    to work on mobile devices.

  • Environment.CurrentDirectory

    This simply calls Directory.GetCurrentDirectory()

  • Assembly.Location

    This would be called using

    this.GetType().Assembly.Location

    This returns the full path to the calling assembly, including the
    assembly name itself. If you are calling a separate class library,
    then its base directory will be returned, such “C:\myassembly.dll” -
    depending obviously on which Assembly instance is being used.

  • Application.StartupPath

    This is inside the System.Windows.Forms namespace, so is typically used in window forms application only.

  • Application.ExecutablePath
    The same as Application.StartupPath, however this also includes the application name, such as “myapp.exe”

Getting the absolute path of the executable, using C#?

MSDN has an article that says to use System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase; if you need the directory, use System.IO.Path.GetDirectoryName on that result.

Or, there's the shorter Application.ExecutablePath which "Gets the path for the executable file that started the application, including the executable name" so that might mean it's slightly less reliable depending on how the application was launched.

Get the root directory of the EXE - C#

Get the location of the currently executing assembly, and go up one level from that directory - like this:

-- get path of the executing assembly
string currentPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

-- get the parent directory for that path
string parentPath = Path.GetFullPath(Path.Combine(currentPath, ".."));

Windows: get the path of an exe by application name or identifier?

There is no global application database you can query for all installed applications. I assume UWP/Store apps are registered somewhere but classic applications do not have to do that.

Some applications register themselves under the app paths key in the registry.

The entries found under App Paths are used primarily for the following purposes:

• To map an application's executable file name to that file's fully qualified path.

• To pre-pend information to the PATH environment variable on a per-application, per-process basis.

Not all applications are registered there. You might want to search the directories listed in %Path% as well.

How to get the path of app(without app.exe)?


path = System.IO.Path.GetDirectoryName( path );

How to get the directory of the .exe for a Node.js pkg executable?

When it comes to the main script it's as simple as finding it:

process.argv

From the Node.js documentation

Pkg from Vercel, is not an installer, its just a packager that will package node binaries and your code in a single exe.

You can follow this tutorial that shows how to make an installer it even enables you to set a path of where you want your exe to be installed



Related Topics



Leave a reply



Submit