如何在VB中获取当前可执行文件的完整路径? [英] How to get the full path of the current executable file in VB?
问题描述
我已经使用VB创建了一个Windows应用程序.每当执行exe
时,我都希望以编程方式获取exe
文件的当前目录.
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.
例如,
现在,我正在执行d:\myApp\test.exe
中的exe
文件.每当我双击exe
文件时,我都想获取exe
文件的路径,例如d:\myApp\test.exe
.
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
.
还,假设我的exe
位于CD或任何记忆棒中,它还会获取exe文件的路径吗?
Also, suppose, my exe
is in CD or any memory stick, will it also get the path of the exe file?
我不知道这有可能吗?
有什么建议吗?
推荐答案
尝试 App.EXEName
.
请注意,在驱动器的根目录中,App.Path
将包含尾随的\
,因此需要有条件地添加任何额外的\
.
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.
因此要获取具有exe
名称的完整路径,请尝试以下操作:
So to get full path with exe
name try this:
App.Path & IIf(Right$(App.Path, 1) <> "\", "\", "") & App.EXEName & ".exe"
此外,它还将为您提供CD或任何记忆棒的路径.
Also, It will give you CD or any memory stick's path too.
这篇关于如何在VB中获取当前可执行文件的完整路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!