[英]Listing all Smart Card Readers on a system (Alcor Micro reader issues)
我已經將此軟件在生產環境中運行了多年,以前從未見過此問題。 我剛收到一台新筆記本電腦(HP EliteBook 8470p),它具有內置的Alcor Micro USB智能卡讀取器 。
下面的代碼將列出系統上的所有讀者,並且工作正常。 我們的某些系統將3或4個閱讀器插入一台計算機。 它已經過十幾種模型的測試,沒有任何問題。
奇怪的是,僅當插入智能卡時,Alcor讀卡器才會列出。 如果我在設備管理器中查看它,它也不會顯示在“智能卡讀卡器”下,直到插入卡為止(除非我轉到“查看”>“顯示隱藏的設備”)。
有誰知道這是為什么,或者是否有辦法確保它在我的軟件中列出?
謝謝。
代碼:
[DllImport("WINSCARD.DLL", EntryPoint = "SCardEstablishContext", CharSet = CharSet.Unicode, SetLastError = true)]
static internal extern uint EstablishContext(ScopeOption scope, IntPtr reserved1,
IntPtr reserved2, ref SmartcardContextSafeHandle context);
[DllImport("WINSCARD.DLL", EntryPoint = "SCardListReaders", CharSet = CharSet.Unicode, SetLastError = true)]
static internal extern uint ListReaders(SmartcardContextSafeHandle context, string groups,
string readers, ref int size);
private bool EstablishContext()
{
if ((this.HasContext))
{
return true;
}
this._lastErrorCode =
(SmartcardErrorCode)UnsafeNativeMethods.EstablishContext(ScopeOption.System,
IntPtr.Zero, IntPtr.Zero, ref this._context);
return (this._lastErrorCode == SmartcardErrorCode.None);
}
public ArrayList ListReaders()
{
ArrayList result = new ArrayList();
//Make sure a context has been established before
//retrieving the list of smartcard readers.
if (this.EstablishContext())
{
//Ask for the size of the buffer first.
int size = this.GetReaderListBufferSize();
//Allocate a string of the proper size in which
//to store the list of smartcard readers.
string readerList = new string('\0', size);
//Retrieve the list of smartcard readers.
this._lastErrorCode =
(SmartcardErrorCode)UnsafeNativeMethods.ListReaders(this._context,
null, readerList, ref size);
if ((this._lastErrorCode == SmartcardErrorCode.None))
{
//Extract each reader from the returned list.
//The readerList string will contain a multi-string of
//the reader names, i.e. they are seperated by 0x00
//characters.
string readerName = string.Empty;
for (int i = 0; i <= readerList.Length - 1; i++)
{
if ((readerList[i] == '\0'))
{
if ((readerName.Length > 0))
{
//We have a smartcard reader's name.
result.Add(readerName);
readerName = string.Empty;
}
}
else
{
//Append the found character.
readerName += new string(readerList[i], 1);
}
}
}
}
return result;
}
順便說一句,這段代碼是由我猜的其他人(由於過多的評論)在網上找到的。 我對它有些熟悉,但從未深入到此。 我嘗試對其進行一些調整,但根本無法將其列出該Alcor讀者。
謝謝!
好的,我在打開賞金后立即找到答案感到非常愚蠢。 我花了一段時間從軟件的角度看待這個問題,並放棄了一會兒-當我再次回顧這個問題時,我認為它可能適合懸賞。
我決定仔細看看我的BIOS選項,然后猜猜是什么? 那里有一個選項,上面寫着“打開智能卡讀卡器電源:a)插入卡時,b)始終”。 我將其更改為“始終”,並且有效。 阿格
因為現在有賞金了,所以它不允許我刪除我的問題,但這基本上是我的答案。 感謝您的意見/建議。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.