16

I have created one windows application using VB. Whenever I executing the exe, I want to get the current directory of the exe file programatically.

For example,

Now, I am executing the exe file in d:\myApp\test.exe. Whenever I double click the exe file I want to get the path of the exe file like d:\myApp\test.exe.

Also, suppose, my exe is in CD or any memory stick, will it also get the path of the exe file?

I don't know is this possible or not?

Any suggestion?

Deanna
  • 23,876
  • 7
  • 71
  • 156
Saravanan
  • 11,372
  • 43
  • 143
  • 213
  • 3
    Just to clarify, you're asking about how to [get the path to the executable](http://stackoverflow.com/a/11738178/588306), not the current, working directory which is different. – Deanna Sep 14 '12 at 12:31
  • @Deanna : yes Deanna you are right...i am asking about get the path to the executable... thanks – Saravanan Sep 15 '12 at 03:38

1 Answers1

39

Try App.Path. It will give you the current exe path. To get exe name you can use App.EXEName. Note that App.Path will contain the trailing \ when in the root of a drive so any extra \ will need to be added conditionally.

So to get full path with exe name try this:

App.Path & IIf(Right$(App.Path, 1) <> "\", "\", "") & App.EXEName & ".exe"

Also, It will give you CD or any memory stick's path too.

MarkJ
  • 30,070
  • 5
  • 68
  • 111
Himanshu
  • 31,810
  • 31
  • 111
  • 133
  • If you use these in the IDE, you will get the path and the filename (minus the .vbp extension) of the project file. – mwfearnley Oct 04 '18 at 13:37