建立资源管理器上下文以使用智能卡 reader

Establish resource manager context to use smart card reader

我正在开发 c++ 应用程序,使用 Visual Studio 2017。

我正在使用 windows 库 winscard。 我从一个简单的项目开始,我调用函数 SCardEstablishContext 作为读取智能卡所需的第一步。

我使用的代码片段如下:

LONG resContext = SCardEstablishContext(SCARD_SCOPE_SYSTEM, NULL, NULL, &hSC);
if (resContext != SCARD_S_SUCCESS) {
    printf("Failed\n");
    printf("Error %X\n", resContext);
}

据我所知,此函数使用名为 "Smart Card" 的 windows 服务来获取执行数据库操作的范围(read/write 卡)。

不幸的是,这个简单的应用程序(即 return SCARD_S_SUCCESS 代码)只能在 windows 7 环境中运行。在我测试的所有 windows 10 个系统中,return 代码总是 0x8010001DL 与断言的定义 SCARD_E_NO_SERVICE 关联:

The Smart Card Resource Manager is not running.

在 windows 7 个系统上,程序在没有管理员权限的情况下工作,在 windows 10 个系统上,我也尝试过使用管理员权限,但错误是一样的。

在我测试的每个 windows 10 个系统中,我在测试我的程序之前手动启动了服务 "Smart Card",并在测试时检查它是否仍然 运行。

在 windows 7 和 windows 10 系统中,我没有连接智能卡 reader。

我使用的 winscard.lib 文件带有 Microsoft Windows SDK 版本 10.0.17763.0

要使其与 windows 10?

一起使用,还需要做一些额外的工作

正如documentation

中所说

The calling application must have appropriate access permissions for any database actions.

这意味着您应该运行 具有管理员权限的程序。

智能卡子系统(和资源管理器)必须工作 "out of the box"。

尝试安装一些向系统提供虚拟插槽的智能卡驱动程序。
例如这个 one.

您是通过 RDP 工作吗?