按键(vb)启动指定目录的程序以及获取当前应用路径

Private Declare Function GetDesktopWindow Lib "user32" () As Long
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal Hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Private Declare Function GetModuleFileName Lib "kernel32" Alias "GetModuleFileNameA" (ByVal hModule As Long, ByVal lpFileName As String, ByVal nSize As Long) As Long
Sub openApp(path)
    Dim P, I, DirPath, ExeName
    P = Split(path, "\")
    For I = 0 To UBound(P) - 1
        DirPath = DirPath & P(I) & "\"
    Next
    ExeName = P(UBound(P))
    ShellExecute GetDesktopWindow, "open", ExeName, vbNullString, DirPath, 5
End Sub

Function appPath()
    str = string(1024, 0)
    GetModuleFileName 0, str, len(str)
    appPath = Replace(str, split(str, "\")(ubound(split(str, "\"))), "")
End Function

 

上面分别是启动指定目录下的应用程序以及查找应用程序所在的当前路径~~~

posted @ 2013-11-14 20:55  前端小小菜  阅读(1762)  评论(0编辑  收藏  举报