获取SmartCard的云端硬盘名称

时间:2012-04-19 14:42:21

标签: windows visual-c++

我正在Windows MFC中编写一个java智能卡应用程序。如何查找连接的智能卡的驱动器名称(名称显示在“我的电脑”中)。例如。一旦我连接智能卡(即使它是智能卡,它将作为存储卡)它将作为“**可移动磁盘(F:)**”。我可以使用SCardConnect功能连接到智能卡。从SCardConnect函数返回句柄,我可以得到驱动器名称。

或者有没有办法找出特定的驱动器是否是智能卡。即。我们可以很容易地找到机器中的可移动磁盘,从中可以找出它是否是智能卡。

提前致谢

1 个答案:

答案 0 :(得分:7)

我编写了用C来枚举SmartCard设备的代码;这是我使用的代码;

干杯, CON

int findDevice(){
hContext = NULL;

log("\nSearching for the following device: XXX eKrypto Pinpad\n");

//Get a context to the resource manager 
lReturn = SCardEstablishContext(SCARD_SCOPE_USER,NULL,NULL,&hContext);
log("Context established.\n");
if(lReturn != SCARD_S_SUCCESS){
  logBytes("SCardEstablishContext failed with error: ", (byte *)&lReturn, sizeof(LONG));
  return 0;
}

contextEstablished = true;

//Get the readers list
DWORD chReaders = 250;
lReturn = SCardListReaders(hContext,NULL,readerNames,&chReaders);
log("Reader List obtained.\n");
if(lReturn != SCARD_S_SUCCESS){
    logBytes("  SCardListReaders failed with error: \n", (byte *)&lReturn, sizeof(LONG));
    return 0;
}

//Search for device
char *pReaders = readerNames;
log(pReaders);
while(strlen(pReaders) != 0 && deviceFound == false){
    if(!memcmp(pReaders, "ETS eKrypto Pinpad", 18)){
        deviceFound = true;
        memcpy(currentReader, pReaders, strlen(pReaders));
    }
    pReaders += strlen (pReaders)+1;
}
if(deviceFound == false){
    log("  Specified ETS device not found\n");
    return 0;
}

log("  Successful\n");
return 1;
}