VB编程问题
VB中,按一个按钮就移动查找一个文件,如QQ.EXE,查找到文件位置后运行这个文件,要完整代码
追问:来自手机问问这么长?!能解释下吗?
VB中,按一个按钮就移动查找一个文件,如QQ.EXE,查找到文件位置后运行这个文件,要完整代码
追问:来自手机问问这么长?!能解释下吗?
答案:Private Declare Function SearchTreeForFile Lib "imagehlp.dll" (ByVal lpRoothPath As String, ByVal lpInputName As String, ByVal lpOutputName As String) As LongPublic Function sysFileFind(ByVal WhichRootPath As String, ByVal WhichFileName As String) As String
Dim iNull As Integer
Dim lResult As Long
Dim sBuffer As String
On Error GoTo L_FILEFINDERROR
sBuffer = String$(1024, 0)
lResult = SearchTreeForFile(WhichRootPath, WhichFileName, sBuffer)
If lResult Then
iNull = InStr(sBuffer, vbNullChar)
If Not iNull Then
sBuffer = Left$(sBuffer, iNull - 1)
End If
sysFileFind = sBuffer
Else
sysFileFind = ""
End If
Exit Function
L_FILEFINDERROR:
MsgBox "查找文件过程中遇到错误!", vbInformation, "查找文件错误"
sysFileFind = Format(Err.Number) & " - " & Err.Description
End FunctionPrivate Sub Command1_Click()
On Error Resume Next
Shell sysFileFind("C:\", "qq.exe"), vbNormalFocusEnd
End Sub