Private Declare Function SearchTreeForFile Lib "ImageHlp.dll" (ByVal lpRoot As String, ByVal lpInPath As String, ByVal lpOutPath As String) As Long
Private Declare Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" (ByVal nDrive As String) As Long
Function SearchFile(ByVal Filename As String) As String
Dim R As Long, i As Long, SearchPath As String
For i = 0 To 25
SearchPath = Chr$(i + 65) & ":\"
If GetDriveType(SearchPath) = 3 Then
SearchFile = String$(1024, 0)
R = SearchTreeForFile(SearchPath, Filename, SearchFile)
If R <> 0 Then SearchFile = Split(SearchFile, Chr(0))(0): Exit Function
End If
Next
SearchFile = "没有找到匹配项!"
End Function
Private Sub Command1_Click()
If SearchFile("WinRAR.exe") <> "没有找到匹配项!" Then '查找WinRAR.exe的路径
Shell SearchFile("WinRAR.exe") & " a c:\压缩后的文件.rar c:\被压缩的文件或文件夹", vbHide
Else
MsgBox "没有找到RAR压缩软件", vbOKOnly, "提示"
End If
End Sub