Chilkat Examples

ChilkatHOME.NET Core C#Android™AutoItCC#C++Chilkat2-PythonCkPythonClassic ASPDataFlexDelphi ActiveXDelphi DLLGoJavaLianjaMono C#Node.jsObjective-CPHP ActiveXPHP ExtensionPerlPowerBuilderPowerShellPureBasicRubySQL ServerSwift 2Swift 3,4,5...TclUnicode CUnicode C++VB.NETVBScriptVisual Basic 6.0Visual FoxProXojo Plugin

SQL Server Examples

Web API Categories

ASN.1
AWS KMS
AWS Misc
Amazon EC2
Amazon Glacier
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Key Vault
Azure Service Bus
Azure Table Service
Base64
Bounced Email
Box
CAdES
CSR
CSV
Certificates
Code Signing
Compression
DKIM / DomainKey
DNS
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
EBICS
ECC
Ed25519
Email Object
Encryption
FTP
FileAccess
Firebase
GMail REST API
GMail SMTP/IMAP/POP
Geolocation
Google APIs
Google Calendar
Google Cloud SQL
Google Cloud Storage
Google Drive
Google Photos
Google Sheets
Google Tasks
Gzip
HTML-to-XML/Text
HTTP

HTTP Misc
IMAP
JSON
JSON Web Encryption (JWE)
JSON Web Signatures (JWS)
JSON Web Token (JWT)
Java KeyStore (JKS)
MHT / HTML Email
MIME
MS Storage Providers
Microsoft Graph
Misc
NTLM
OAuth1
OAuth2
OIDC
Office365
OneDrive
OpenSSL
Outlook
Outlook Calendar
Outlook Contact
PDF Signatures
PEM
PFX/P12
PKCS11
POP3
PRNG
REST
REST Misc
RSA
SCP
SCard
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
ScMinidriver
SharePoint
SharePoint Online
Signing in the Cloud
Socket/SSL/TLS
Spider
Stream
Tar Archive
ULID/UUID
Upload
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Zip
curl
uncategorized

 

 

 

(SQL Server) PC/SC Find Inserted Smart Cards

See more SCard Examples

Get detailed information about each reader including whether or not a smart card is currently inserted in the reader. (Also includes USB tokens.)

Note: This functionality was introduced in Chilkat v9.5.0.87.

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

// Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
//
CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr int
    DECLARE @sTmp0 nvarchar(4000)
    -- This example requires the Chilkat API to have been previously unlocked.
    -- See Global Unlock Sample for sample code.

    DECLARE @scard int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.SCard', @scard OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    -- First establish a context to the PC/SC Resource Manager
    DECLARE @success int
    EXEC sp_OAMethod @scard, 'EstablishContext', @success OUT, 'user'
    IF @success = 0
      BEGIN
        EXEC sp_OAGetProperty @scard, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @scard
        RETURN
      END

    -- Get JSON containing information about the smartcards currently inserted into readers.
    -- This also includes information about USB security tokens.
    DECLARE @json int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.JsonObject', @json OUT

    EXEC sp_OAMethod @scard, 'FindSmartcards', @success OUT, @json
    IF @success = 0
      BEGIN
        EXEC sp_OAGetProperty @scard, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @scard
        EXEC @hr = sp_OADestroy @json
        RETURN
      END

    EXEC sp_OASetProperty @json, 'EmitCompact', 0
    EXEC sp_OAMethod @json, 'Emit', @sTmp0 OUT
    PRINT @sTmp0

    -- Here is sample output:
    -- See below for sample code to parse the JSON.

    -- You can see which readers have a card inserted by the "state".
    -- If the state contains "present", then a card is inserted into the reader.
    -- (USB tokens will typically always have a state containing "present")
    -- Also, the ATR of the card inserted into the reader is indicated by "atr".

    -- {
    --   "reader": [
    --     {
    --       "name": "Alcor Micro USB Smart Card Reader 0",
    --       "state": "present,inuse",
    --       "vendorName": "Alcor Micro",
    --       "systemName": "Alcor Micro USB Smart Card Reader 0",
    --       "card": {
    --         "atr": "3B7F96000080318065B0855956FB120FFE829000",
    --         "windows": {
    --           "miniDriver": "AxaltoCM.dll",
    --           "cryptoProvider": "Microsoft Base Smart Card Crypto Provider",
    --           "keyStorageProvider": "Microsoft Smart Card Key Storage Provider"
    --         }
    --       }
    --     },
    --     {
    --       "name": "FS USB Token 0",
    --       "state": "present,inuse",
    --       "vendorName": "FS",
    --       "serialNumber": "3F",
    --       "systemName": "FS USB Token 0",
    --       "card": {
    --         "atr": "3B9F958131FE9F006646530534002571DF000000000012",
    --         "windows": {
    --           "miniDriver": "eps2003csp11",
    --           "cryptoProvider": "Microsoft Base Smart Card Crypto Provider",
    --           "keyStorageProvider": "Microsoft Smart Card Key Storage Provider"
    --         }
    --       }
    --     },
    --     {
    --       "name": "FT Java Token 0",
    --       "state": "present",
    --       "vendorName": "FT",
    --       "serialNumber": "3F",
    --       "systemName": "FT Java Token 0",
    --       "card": {
    --         "atr": "3BFC180000813180459067464A00642D70C172FEE0FE",
    --         "windows": {
    --           "miniDriver": "tagliov70px.dll",
    --           "cryptoProvider": "Microsoft Base Smart Card Crypto Provider",
    --           "keyStorageProvider": "Microsoft Smart Card Key Storage Provider"
    --         }
    --       }
    --     },
    --     {
    --       "name": "SCM Microsystems Inc. SCR33x USB Smart Card Reader 0",
    --       "state": "present",
    --       "vendorName": "SCM Microsystems Inc.",
    --       "serialNumber": "333130303330",
    --       "systemName": "SCM Microsystems Inc. SCR33x USB Smart Card Reader 0",
    --       "card": {
    --         "atr": "3BFC180000813180459067464A00641606F2727E00E0",
    --         "windows": {
    --           "miniDriver": "tagliov70px.dll",
    --           "cryptoProvider": "Microsoft Base Smart Card Crypto Provider",
    --           "keyStorageProvider": "Microsoft Smart Card Key Storage Provider"
    --         }
    --       }
    --     },
    --     {
    --       "name": "Yubico YubiKey OTP+FIDO+CCID 0",
    --       "state": "present",
    --       "vendorName": "Yubico",
    --       "serialNumber": "3F",
    --       "systemName": "Yubico YubiKey OTP+FIDO+CCID 0",
    --       "card": {
    --         "atr": "3BFD1300008131FE158073C021C057597562694B657940",
    --         "windows": {
    --           "miniDriver": "msclmd.dll",
    --           "cryptoProvider": "Microsoft Base Smart Card Crypto Provider",
    --           "keyStorageProvider": "Microsoft Smart Card Key Storage Provider"
    --         }
    --       }
    --     }
    --   ]
    -- }

    -- Use this online tool to generate parsing code from sample JSON: 
    -- Generate Parsing Code from JSON

    DECLARE @name nvarchar(4000)

    DECLARE @state nvarchar(4000)

    DECLARE @vendorName nvarchar(4000)

    DECLARE @systemName nvarchar(4000)

    DECLARE @cardAtr nvarchar(4000)

    DECLARE @cardWindowsMiniDriver nvarchar(4000)

    DECLARE @cardWindowsCryptoProvider nvarchar(4000)

    DECLARE @cardWindowsKeyStorageProvider nvarchar(4000)

    DECLARE @serialNumber nvarchar(4000)

    DECLARE @i int
    SELECT @i = 0
    DECLARE @count_i int
    EXEC sp_OAMethod @json, 'SizeOfArray', @count_i OUT, 'reader'
    WHILE @i < @count_i
      BEGIN
        EXEC sp_OASetProperty @json, 'I', @i
        EXEC sp_OAMethod @json, 'StringOf', @name OUT, 'reader[i].name'
        EXEC sp_OAMethod @json, 'StringOf', @state OUT, 'reader[i].state'
        EXEC sp_OAMethod @json, 'StringOf', @vendorName OUT, 'reader[i].vendorName'
        EXEC sp_OAMethod @json, 'StringOf', @systemName OUT, 'reader[i].systemName'
        EXEC sp_OAMethod @json, 'StringOf', @cardAtr OUT, 'reader[i].card.atr'
        EXEC sp_OAMethod @json, 'StringOf', @cardWindowsMiniDriver OUT, 'reader[i].card.windows.miniDriver'
        EXEC sp_OAMethod @json, 'StringOf', @cardWindowsCryptoProvider OUT, 'reader[i].card.windows.cryptoProvider'
        EXEC sp_OAMethod @json, 'StringOf', @cardWindowsKeyStorageProvider OUT, 'reader[i].card.windows.keyStorageProvider'
        EXEC sp_OAMethod @json, 'StringOf', @serialNumber OUT, 'reader[i].serialNumber'
        SELECT @i = @i + 1
      END

    -- Applications should always release the context when finished.
    EXEC sp_OAMethod @scard, 'ReleaseContext', @success OUT
    IF @success = 0
      BEGIN
        EXEC sp_OAGetProperty @scard, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
      END

    EXEC @hr = sp_OADestroy @scard
    EXEC @hr = sp_OADestroy @json


END
GO

 

© 2000-2024 Chilkat Software, Inc. All Rights Reserved.