Establish resource manager context to use smart card reader
Asked Answered
B

2

6

I'm developing a c++ application, using Visual Studio 2017.

I'm using the windows library winscard. I'm starting with a simple project where i'm calling the function SCardEstablishContext as the first step needed to read a smart card.

The snippet of code i'm using is the following:

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

What i know is that this function use the windows service called "Smart Card" to get the scope within which database operations are performed (read/write cards).

Unfortunately this simple application works (i.e. return the SCARD_S_SUCCESS code) only in windows 7 environment. In all the windows 10 systems that i tested the return code is always 0x8010001DL that is associated to the define SCARD_E_NO_SERVICE that assert:

The Smart Card Resource Manager is not running.

On windows 7 systems the program works without admin privileges, on windows 10 systems i've tried with admin privileges too but the error is the same.

In every windows 10 system that i tested i manually started the service "Smart Card" before testing my program and checked that it still running while testing.

In both windows 7 and windows 10 systems i don't have a smart card reader connected.

The winscard.lib file i use come with Microsoft Windows SDK version 10.0.17763.0

There's something extra to do to get it works with windows 10?

Betti answered 31/5, 2019 at 15:33 Comment(8)
Smart Card Subsystem (and Resource Manger) must work "out of the box". Try to install some smart card drivers that present virtual slots to the system. For example this oneEnisle
Are you working via RDP?Enisle
@Enisle thanks to point that out, i was! I've tried my program on the device directly and now the function returns SCARD_S_SUCCESS, but why this behaviour? I'm still unable to get it work on win10 pc without a smart card connected. Installing that smart card driver didn't help. Maybe connecting a readed can resolve (i don't have one atm)?Betti
I have a virtual token that can be "inserted" an then will be visible through Smart Card Resource Manger. I can share it with you, but do not see private way to communicate.Enisle
@Enisle thank you, but on next week i'll have an usb card reader and i'll see. The important part was to communicate with the reader on the tablet and i've achieved it. Please add an answer so i can assign the bounty.Betti
How is your progress?Enisle
@Enisle With the card reader connected all is working fine. Thanks!Betti
Nice to hear it!Enisle
E
5

Smart Card Subsystem (and Resource Manger) must work "out of the box".

Try to install some smart card drivers that present virtual slots to the system.
For example this one.

Are you working via RDP?

Enisle answered 7/6, 2019 at 12:21 Comment(2)
I answered "yes" to the RDP question. I logged into the computer directly, and magic: I see the smart card reader. I guess it's a security feature so you don't share your smartcard with the world.Burnet
Ah, RDP. Lost too much time again due to this, not the first time. Even with Smart card forwarding disabled, you just get that terrible uninformative message.Leaper
R
0

As it said in documentation

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

It means that you should run the program with admin privileges.

Ringdove answered 6/6, 2019 at 15:30 Comment(1)
Yes, i didn't mention in my question but i tried with admin privileges too, but the result is the same.Betti

© 2022 - 2025 — McMap. All rights reserved.