ICertAdmin::SetRequestAttributes 方法 (certadm.h)

SetRequestAttributes 方法會在指定的擱置憑證要求中設定屬性。 這個方法最初是在 ICertAdmin 介面中定義。

若要讓這個方法成功,憑證要求必須擱置中。

語法

HRESULT SetRequestAttributes(
  [in] const BSTR strConfig,
  [in] LONG       RequestId,
  [in] const BSTR strAttributes
);

參數

[in] strConfig

代表 證書頒發機構單位 (CA) 伺服器的有效組態字串,格式為 COMPUTERNAME\CANAME,其中 COMPUTERNAME 是證書服務伺服器的網路名稱,CANAME 是證書頒發機構單位的一般名稱,如憑證服務設定期間所輸入。 如需設定字串名稱的相關信息,請參閱 ICertConfig

重要SetRequestAttributes 不會在設定字串變更時清除內部快取。 當您變更 CA 的組態字串時,必須具現化新的 ICertAdmin 物件,並使用新的組態字串再次呼叫此方法。
 

[in] RequestId

指定接收 屬性的要求識別碼

[in] strAttributes

指定屬性數據。 每個屬性都是名稱/值字串組。 冒號字元會分隔名稱和值,而換行符元會分隔多個名稱/值組,例如:

C++ AttributeName1AttributeValue1\nAttributeName2AttributeValue2
VB AttributeName1AttributeValue1 & vbNewLine & AttributeName2AttributeValue2
可能新增至要求的要求屬性數目沒有設定的限制。

當憑證服務剖析屬性名稱時,它會忽略空格、連字元 (減號) 和大小寫。 例如, AttributeName1Attribute Name1Attribute-name1 全都相等。 對於屬性值,憑證服務會忽略前置和尾端空格符。

注意 屬性名稱的最大長度為 127 個非 NULL 字元。 屬性值的最大長度為 4,096 個非 NULL 字元。
 

傳回值

VB

如果方法成功,方法會傳回S_OK。

如果方法失敗,它會傳回指出錯誤的 HRESULT 值。 如需常見錯誤碼的清單,請參閱 一般 HRESULT 值

備註

藉由呼叫 SetRequestAttributes 新增或更新的屬性不會改變與憑證要求相關聯的初始未剖析屬性字串。 憑證要求的未剖析屬性字串在要求憑證之後, (ICertRequest::Submit 方法會允許在要求憑證時指定屬性) 。

您可以使用憑證頒發機構單位 MMC 嵌入式管理單元來顯示初始未剖析的要求屬性字串。

當您檢視剖析的屬性時,也會因為 呼叫 SetRequestAttributes 而看到任何變更。

檢視剖析的屬性

  1. 開啟證書頒發機構單位 MMC 嵌入式管理單元。
  2. 開啟 [擱置的要求] 資料夾。
  3. 以滑鼠右鍵按下要求,指向 [ 所有工作],然後按兩下 [ 檢視屬性/延伸模組]。
若要列舉或檢視所有剖析的屬性,包括透過 SetRequestAttributes 新增的屬性,您也可以使用 IEnumCERTVIEWATTRIBUTE 介面。

系統管理工作使用DCOM。 呼叫此介面方法的程式代碼,如舊版 Certadm.h 中所定義,只要客戶端和伺服器都執行相同的 Windows 作業系統,就會在 Windows 伺服器上執行。

範例

    BSTR bstrAttribs = NULL;
    BSTR bstrCA = NULL;
    long nReqID;  // request ID

    //  Specify the attributes.
    //  For example, "AttName1:AttValue1\nAttName2:AttValue2". 
    bstrAttribs = SysAllocString(L"<ATTRIBUTESHERE>");
    if (NULL == bstrAttribs)
    {
        printf("Memory allocation failed for bstrAttribs.\n");
        goto error;
    }
    
    bstrCA = SysAllocString(L"<COMPUTERNAMEHERE>\\<CANAMEHERE>");
    if (NULL == bstrCA)
    {
        printf("Memory allocation failed for bstrCA.\n");
        goto error;
    }

    //  Request ID to receive the attributes.
    nReqID = <REQUESTIDHERE>;

    //  Add these attributes to the certificate.
    //  pCertAdmin is a previously instantiated
    //  ICertAdmin object pointer. 
    hr = pCertAdmin->SetRequestAttributes( bstrCA,
                                           nReqID,
                                           bstrAttribs );
    if (FAILED(hr))
        printf("Failed SetRequestAttributes [%x]\n", hr);
    else
        printf("SetRequestAttributes succeeded\n");

    //  Done processing.

error:

    if (bstrAttribs)
        SysFreeString(bstrAttribs);
    if (bstrCA)
        SysFreeString(bstrCA);
    //  Free other resources.

規格需求

需求
最低支援的用戶端 都不支援
最低支援的伺服器 Windows Server 2003 [僅限桌面應用程式]
目標平台 Windows
標頭 certadm.h (包含 Certsrv.h)
程式庫 Certidl.lib
Dll Certadm.dll

另請參閱

CCertAdmin

ICertAdmin

ICertAdmin2

ICertConfig

IEnumCERTVIEWATTRIBUTE