• 欢迎访问金刀客博客!
  • 2019,春节快乐!

VB中获取exe自身所在路径的几种方法

原创天空 admin 9794次浏览 已收录 0个评论

VB中获取exe自身所在路径的几种方法。
1,利用App.Path

Private Sub Command1_Click()
Dim strpath1 As String
If Right(App.Path, 1) = “\” Then
strpath1 = App.Path & App.EXEName & “.exe”
Else
strpath1 = App.Path & “\” & App.EXEName & “.exe”
End If
MsgBox strpath1
End Sub

或者

Private Sub Command3_Click()
Dim strpath As String
strpath = IIf(Right(App.Path, 1) = “\”, App.Path, App.Path & “\”) & App.EXEName & “.exe”
MsgBox strpath
End Sub

2,利用API

Private Declare Function GetModuleFileName Lib “kernel32” Alias “GetModuleFileNameA” (ByVal hModule As Long, ByVal lpFileName As String, ByVal nSize As Long) As Long
Private Sub Command2_Click()
Dim strpath As String
strpath = Space(256)
GetModuleFileName 0, strpath, 256
MsgBox strpath
End Sub


金刀客博客 , 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明VB中获取exe自身所在路径的几种方法
喜欢 (19)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到