Windows application path in net




















Martin Prikryl k 47 47 gold badges silver badges bronze badges. Linda Linda 2 2 gold badges 3 3 silver badges 6 6 bronze badges. Is your code in the exe or an a. Add a comment. Active Oldest Votes. StartupPath Full. Nick Craver Nick Craver k gold badges silver badges bronze badges.

Is this in a namespace that I need to import? Mark Hurd Mark Hurd ColeJohnson I have asked on meta to clarify this.

Uwe Keim Eddy Jawed Eddy Jawed 5 5 silver badges 17 17 bronze badges. Alireza Nemeti Alireza Nemeti 6 6 bronze badges. StartupPath TextBox2. StartupPath TextBox3. Right Application. Text - 9 TextBox4. Left Application. I use: Imports System. Corey B Corey B 15 3 3 bronze badges. Thanks for clarifying the fact that GetRuntimeDirectory always returns the 2. This is the correct behavior in most cases, where you want to access the framework tools, which are in 2.

How can I get InstallRoot for x86 and x NET frameworks on 64bit systems? NET, even on 64bit systems? I need to get path to this folder with non-managed application, so I can't use the method you listed above.

Probably the easiest would be to create tiny. NET applications, one compiled for x86 e. Unmanaged application would then start a child process for x86 getdotnetpath Then it would start a child process for x64 getdotnetpath GetDirectoryName System. An easier way is to include the Microsoft. Utilities assembly and use using Microsoft. Utilities; ToolLocationHelper. VersionLatest ;. Brian Rudolph Brian Rudolph 5, 2 2 gold badges 22 22 silver badges 18 18 bronze badges. That sounds a lot better, especially when working on tools that affect the build process.

I guess this won't work for. NET Core and. NET 5. You can grab it from the Windows Registry: using System; using Microsoft. GetValue "InstallRoot". Major, Environment. Minor, Environment.

Christian C. I strongly advice against accessing registry directly on a 64bit operating system this may actually give wrong answer. StartupPath as usual. This works for both ASP. Net and winform applications. It also does not require any reference to System. Web assemblies. Location or Assembly.

Use in combination with System. GetDirectoryName to get only the directory. The paths from GetEntryAssembly and GetExecutingAssembly can be different, even though for most cases the directory will be the same.

Not sure about C I didn't see anyone convert the LocalPath provided by. Net Core reflection into a usable System. IO path so here's my version. NET Core 3 and above you will get the. To get the. None of these methods work in special cases like using a symbolic link to the exe, they will return the location of the link not the actual exe.

GetDirectoryName System. FileName Is the only one that has worked for me in every case I have tried. Here is a reliable solution that works with 32bit and 64bit applications.

Notice that if you know the id of the process, then this method will return the corresponding ExecutePath. Id, etc. Kill, etc. You can create a folder name as Resources within the project using Solution Explorer,then you can paste a file within the Resources. Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams?

Collectives on Stack Overflow. Learn more. How can I get the application's path in a. NET console application? Ask Question. Asked 12 years, 8 months ago.

Active 1 month ago. Viewed 1. How do I find the application's path in a console application? Peter Mortensen JSmyth JSmyth Do you install. This is the best way if you want to drop away further future exceptions!

BaseDirectory is app directory. Be aware that application can behave different in VS env and Win env. But AppDomain should be same not as application. Add a comment. Active Oldest Votes. Location 1 Combine that with System. Sebastian Brosch Sam Axe Sam Axe CodeBase will return the ' permenant ' path of the assembly. SamGoldberg: That depend on how it is used: stackoverflow.

Or you can LocalPath — Mr. GetExecutingAssembly returns assembly that contains the code that is currently executing. This may not necessarily be the console. It may be an assembly that has been loaded from a totally different location. You will have to use GetEntryAssembly! The better alternative is AppDomain. Please write code in 4 spaces so it is comfortable to copy — fnc Show 13 more comments.

You can use the following code to get the current application directory. Richard Ev Sarathy Sarathy. Don't use this. The BaseDirectory can be set at runtime. It is not guaranteed to be correct like the accepted answer is. It only has a getter. Show 1 more comment. GetDirectoryName path ;. Sabuncu 4, 4 4 gold badges 43 43 silver badges 82 82 bronze badges.

Mindor Mr. Mindor 3, 2 2 gold badges 17 17 silver badges 25 25 bronze badges. Just wanted to say, obviously there are many more than 2 options by how many other choices are posted LocalPath; — Scott Solmer.

This is just wrong. What is the executable is not a. NET assembly at all?



0コメント

  • 1000 / 1000