查看: 22  |  回复: 0
  VB6 得到文件是什么关联软件打开的,子程序 FindExecutable(s As String)
楼主
发表于 昨天 16:44

新建From1(窗体),新建Command1(按钮CommandButton),代码:

Private Const MAX_FILENAME_LEN = 256

Private Declare Function FindExecutableA Lib "shell32.dll" (ByVal lpFile As String, ByVal lpDirectory As String, ByVal lpResult As String) As Long

Private Function FindExecutable(s As String) As String
   Dim i As Integer
   Dim s2 As String
   
   s2 = String(MAX_FILENAME_LEN, 32) & Chr$(0)
   
   i = FindExecutableA(s & Chr$(0), vbNullString, s2)
   
   If i > 32 Then
      FindExecutable = Left$(s2, InStr(s2, Chr$(0)) - 1)
   Else
      FindExecutable = ""
   End If
End Function

Private Sub Command1_Click()
    MsgBox FindExecutable(App.Path & "/123.txt")
End Sub

运行结果:

C:\Windows\system32\NOTEPAD.EXE


您需要登录后才可以回帖 登录 | 立即注册
【本版规则】请勿发表违反国家法律的内容,否则会被冻结账号和删贴。
用户名: 立即注册
密码:
2020-2024 MaNongKu.com