按键(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
上面分别是启动指定目录下的应用程序以及查找应用程序所在的当前路径~~~