如何知道客户端PC上是否有PDF阅读器

发布于 2024-08-20 21:19:07 字数 161 浏览 7 评论 0原文

我需要知道是否有任何方法可以使用 VB6 检测客户端 PC (Windows) 中是否有任何 PDF 阅读器(Adobe Reader、Foxit Reader...)。 NET(C#)。

我无法通过读取Windows注册表来做到这一点,因为用户可能没有读取它的权限。

谢谢。

I need to know if there is any way to detect in a client PC (Windows) there any PDF reader (Adobe Reader, Foxit Reader, ...), using VB6 and. NET (C #).

I can not do by reading the Windows registry, because the user may not have permissions to read it.

Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

临风闻羌笛 2024-08-27 21:19:07

基于 Jerry Coffin 建议使用 FindExecutable 的示例(基于

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

Private Declare Function lstrlen Lib "kernel32.dll" _
  Alias "lstrlenA" ( _
  ByVal lpString As Any) As Long

' FindExecutable Constants
Private Const ERROR_FILE_NOT_FOUND = 2&
Private Const ERROR_PATH_NOT_FOUND = 3&
Private Const ERROR_BAD_FORMAT = 11&

Private Sub Command1_Click()
  Dim Retval As Long, buffer As String

  ' init buffer 
  buffer = Space(256)

  Retval = FindExecutable("c:\windows\media\tada.wav", "", buffer)

  Select Case Retval
    Case 0
      Debug.Print "Not enough memory to execute this method." 
    Case 31
      Debug.Print "No file association found."
    Case ERROR_FILE_NOT_FOUND
      Debug.Print "File not found."
    Case ERROR_PATH_NOT_FOUND
      Debug.Print "Path not found."
    Case ERROR_BAD_FORMAT
      Debug.Print "The associated application is not a valid Win32 executable."
    Case Else
      Debug.Print "Associated application: " & Left$(buffer, lstrlen(buffer))
  End Select
End Sub

A sample based on Jerry Coffin's suggestion to use FindExecutable (based on this article):

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

Private Declare Function lstrlen Lib "kernel32.dll" _
  Alias "lstrlenA" ( _
  ByVal lpString As Any) As Long

' FindExecutable Constants
Private Const ERROR_FILE_NOT_FOUND = 2&
Private Const ERROR_PATH_NOT_FOUND = 3&
Private Const ERROR_BAD_FORMAT = 11&

Private Sub Command1_Click()
  Dim Retval As Long, buffer As String

  ' init buffer 
  buffer = Space(256)

  Retval = FindExecutable("c:\windows\media\tada.wav", "", buffer)

  Select Case Retval
    Case 0
      Debug.Print "Not enough memory to execute this method." 
    Case 31
      Debug.Print "No file association found."
    Case ERROR_FILE_NOT_FOUND
      Debug.Print "File not found."
    Case ERROR_PATH_NOT_FOUND
      Debug.Print "Path not found."
    Case ERROR_BAD_FORMAT
      Debug.Print "The associated application is not a valid Win32 executable."
    Case Else
      Debug.Print "Associated application: " & Left$(buffer, lstrlen(buffer))
  End Select
End Sub
怪异←思 2024-08-27 21:19:07

创建扩展名为“.pdf”的临时文件,然后使用 FindExectuable 作为您的临时文件。请注意,即使只有扩展名确实很重要,FindExecutable 仍然需要一个真实的文件,而不仅仅是具有正确扩展名的名称。

Create a temporary file with an extension of ".pdf", and then use FindExectuable for your temporary file. Note that even though only the extension really matters, FindExecutable still requires a real file, not just a name with the right extension.

思念满溢 2024-08-27 21:19:07

该 VB 例程将获取文件扩展名的默认可执行文件。如果没有可执行文件,则用户没有配置程序来处理扩展。

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

Function GetAssociation(ByVal Path As String, ByVal FileName As String) As String
   Dim Result As String
   Dim x As Long
   Dim lngLenBuff

   lngLenBuff = 256
   Result = String(lngLenBuff, vbNullChar)
   x = FindExecutable(FileName, Path, Result)
   GetAssociation = Left$(Result, InStr(Result, Chr$(0)) - 1) 'get string to left of the null'
End Function

This VB routine will get the default executable for a file extension. If there is no executable then the user does not have a program configured to handle the extension.

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

Function GetAssociation(ByVal Path As String, ByVal FileName As String) As String
   Dim Result As String
   Dim x As Long
   Dim lngLenBuff

   lngLenBuff = 256
   Result = String(lngLenBuff, vbNullChar)
   x = FindExecutable(FileName, Path, Result)
   GetAssociation = Left$(Result, InStr(Result, Chr$(0)) - 1) 'get string to left of the null'
End Function
你的呼吸 2024-08-27 21:19:07

我知道问题是针对 VB 的,但在 C# 中找到了 FindExecutable 的一个不错的实现 这里

using System;
using System.Text;
using System.Runtime.InteropServices;

namespace PaytonByrd {
public class Win32API
{
  [DllImport("shell32.dll", EntryPoint="FindExecutable")] 
  public static extern long FindExecutableA(
    string lpFile, string lpDirectory, StringBuilder lpResult);

  public static string FindExecutable(
    string pv_strFilename)
  {
    StringBuilder objResultBuffer = 
      new StringBuilder(1024);
    long lngResult = 0;

    lngResult = 
      FindExecutableA(pv_strFilename, 
        string.Empty, objResultBuffer);

    if(lngResult >= 32)
    {
        return objResultBuffer.ToString();
    }

    return string.Format(
      "Error: ({0})", lngResult);
  }
}}

这是一个用法示例:

using System;
using System.Diagnostics;
using System.IO;
using PaytonByrd;

namespace CSharpFindExecutableTester
{
  class Class1
  {
    [STAThread]
    static void Main(string[] args)
    {
      foreach(string strFile in 
        Directory.GetFiles("c:\\"))
      {
        string strOutput = 
          string.Format(
            "{0} - Application: {1}",
            strFile, 
            Win32API.FindExecutable(
              strFile));

        Debug.WriteLine(strOutput);
      }
    }
  }
}

I know the question was for VB, but found a decent implementation of FindExecutable in C# here:

using System;
using System.Text;
using System.Runtime.InteropServices;

namespace PaytonByrd {
public class Win32API
{
  [DllImport("shell32.dll", EntryPoint="FindExecutable")] 
  public static extern long FindExecutableA(
    string lpFile, string lpDirectory, StringBuilder lpResult);

  public static string FindExecutable(
    string pv_strFilename)
  {
    StringBuilder objResultBuffer = 
      new StringBuilder(1024);
    long lngResult = 0;

    lngResult = 
      FindExecutableA(pv_strFilename, 
        string.Empty, objResultBuffer);

    if(lngResult >= 32)
    {
        return objResultBuffer.ToString();
    }

    return string.Format(
      "Error: ({0})", lngResult);
  }
}}

Here's a usage example:

using System;
using System.Diagnostics;
using System.IO;
using PaytonByrd;

namespace CSharpFindExecutableTester
{
  class Class1
  {
    [STAThread]
    static void Main(string[] args)
    {
      foreach(string strFile in 
        Directory.GetFiles("c:\\"))
      {
        string strOutput = 
          string.Format(
            "{0} - Application: {1}",
            strFile, 
            Win32API.FindExecutable(
              strFile));

        Debug.WriteLine(strOutput);
      }
    }
  }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文