根据文件类型调用系统默认未知应用程序开启该文件
这是以前一位给的程序
Option Explicit
’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’
’ Copyright ?1996-2004 VBnet, Randy Birch, All Rights Reserved.
’ Some pages may also contain other copyrights by the author.
’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’
’ Distribution: You can freely use this code in your own
’ applications, but you may not reproduce
’ or publish this code on any web site,
’ online service, or distribute as source
’ on any media without express permission.
’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’
Private Declare Function FindExecutable Lib "shell32" _
Alias "FindExecutableA" _
(ByVal lpFile As String, _
ByVal lpDirectory As String, _
ByVal sResult As String) As LongPrivate Const MAX_PATH As Long = 260
Private Const ERROR_FILE_NO_ASSOCIATION As Long = 31
Private Const ERROR_FILE_NOT_FOUND As Long = 2
Private Const ERROR_PATH_NOT_FOUND As Long = 3
Private Const ERROR_FILE_SUCCESS As Long = 32 ’my constant
Private Const ERROR_BAD_FORMAT As Long = 11Private Sub Command1_Click() Dim success As Long
Dim pos As Long
Dim sResult As String
Dim msg As String
sResult = Space$(MAX_PATH) ’lpFile: name of the file of interest
’lpDirectory: location of lpFile
’sResult: path and name of executable associated with lpFile
success = FindExecutable("winhlp32.hlp", "c:\winnt\system32\", sResult)
Select Case success
Case ERROR_FILE_NO_ASSOCIATION: msg = "no association"
Case ERROR_FILE_NOT_FOUND: msg = "file not found"
Case ERROR_PATH_NOT_FOUND: msg = "path not found"
Case ERROR_BAD_FORMAT: msg = "bad format"
Case Is >= ERROR_FILE_SUCCESS: ‘在这行出现错误“缺少:=或<>或><或>=或=>或 <=或=<”
pos = InStr(sResult, Chr$(0))
If pos Then
msg = Left$(sResult, pos - 1)
End If
End Select
MsgBox msg
End Sub
请各位帮忙看看哪错了
这是以前一位给的程序
Option Explicit
’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’
’ Copyright ?1996-2004 VBnet, Randy Birch, All Rights Reserved.
’ Some pages may also contain other copyrights by the author.
’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’
’ Distribution: You can freely use this code in your own
’ applications, but you may not reproduce
’ or publish this code on any web site,
’ online service, or distribute as source
’ on any media without express permission.
’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’
Private Declare Function FindExecutable Lib "shell32" _
Alias "FindExecutableA" _
(ByVal lpFile As String, _
ByVal lpDirectory As String, _
ByVal sResult As String) As LongPrivate Const MAX_PATH As Long = 260
Private Const ERROR_FILE_NO_ASSOCIATION As Long = 31
Private Const ERROR_FILE_NOT_FOUND As Long = 2
Private Const ERROR_PATH_NOT_FOUND As Long = 3
Private Const ERROR_FILE_SUCCESS As Long = 32 ’my constant
Private Const ERROR_BAD_FORMAT As Long = 11Private Sub Command1_Click() Dim success As Long
Dim pos As Long
Dim sResult As String
Dim msg As String
sResult = Space$(MAX_PATH) ’lpFile: name of the file of interest
’lpDirectory: location of lpFile
’sResult: path and name of executable associated with lpFile
success = FindExecutable("winhlp32.hlp", "c:\winnt\system32\", sResult)
Select Case success
Case ERROR_FILE_NO_ASSOCIATION: msg = "no association"
Case ERROR_FILE_NOT_FOUND: msg = "file not found"
Case ERROR_PATH_NOT_FOUND: msg = "path not found"
Case ERROR_BAD_FORMAT: msg = "bad format"
Case Is >= ERROR_FILE_SUCCESS: ‘在这行出现错误“缺少:=或<>或><或>=或=>或 <=或=<”
pos = InStr(sResult, Chr$(0))
If pos Then
msg = Left$(sResult, pos - 1)
End If
End Select
MsgBox msg
End Sub
请各位帮忙看看哪错了
Dim pos As Long
Dim sResult As String
Dim msg As String
sResult = Space$(MAX_PATH) 'lpFile: name of the file of interest
'lpDirectory: location of lpFile
'sResult: path and name of executable associated with lpFile
success = FindExecutable("Readme.htm", "C:\Windows\", sResult)
Select Case success
Case ERROR_FILE_NO_ASSOCIATION: msg = "no association"
Case ERROR_FILE_NOT_FOUND: msg = "file not found"
Case ERROR_PATH_NOT_FOUND: msg = "path not found"
Case ERROR_BAD_FORMAT: msg = "bad format"
Case Is >= ERROR_FILE_SUCCESS:
pos = InStr(sResult, Chr$(0))
If pos Then
msg = Left$(sResult, pos - 1)
End If
End Select
MsgBox msg
End Sub
Const MAX_FILENAME_LEN = 260
Private Declare Function FindExecutable Lib "shell32.dll" Alias "FindExecutableA" (ByVal lpFile As String, ByVal lpDirectory As String, ByVal lpResult As String) As Long
Private Sub Form_Load()
'KPD-Team 1999
'URL: http://www.allapi.net/
'E-Mail: [email protected]
Dim i As Integer, s2 As String
Const sFile = "C:\Windows\Readme.txt"
'Check if the file exists
If Dir(sFile) = "" Or sFile = "" Then
MsgBox "File not found!", vbCritical
Exit Sub
End If
'Create a buffer
s2 = String(MAX_FILENAME_LEN, 32)
'Retrieve the name and handle of the executable, associated with this file
i = FindExecutable(sFile, vbNullString, s2)
If i > 32 Then
MsgBox Left$(s2, InStr(s2, Chr$(0)) - 1)
Else
MsgBox "No association found !"
End If
End Sub