> ## Documentation Index
> Fetch the complete documentation index at: https://devdocs.xbox.com/llms.txt
> Use this file to discover all available pages before exploring further.

# XtfGetCredentialInfoList

> XtfGetCredentialInfoList

# XtfGetCredentialInfoList

傳回 `XtfNetworkCredentials` 物件，其中包含目前儲存在主機上的認證清單。

<a id="syntaxSection" />

## 語法

```cpp theme={null}
HRESULT XtfGetCredentialInfoList(
         LPCWSTR address,
         XtfNetworkCredentials* credentialInfo
)  
```

<a id="ID4EG" />

### 參數

*address*<br />類型：LPCWSTR

\[in] 主機的位址。

*credentialInfo*<br />類型：XtfNetworkCredentials\*

\[out] `XtfNetworkCredentials` 物件，其中包含目前儲存在主機上的認證清單。

<a id="ID4EN" />

### 傳回值

類型：HRESULT

傳回值為 `S_OK` 表示函式成功，且可以從 **credentialInfo** 物件擷取認證資訊。任何其他值都表示發生非預期的錯誤。

<a id="remarks" />

## 備註

使用 [XtfAddCredential](/zh-TW/reference/tools/xtf/xtfapi/functions/xtfaddcredential-xtfapi-xbox-windows-m) 新增認證。使用 [XtfRemoveCredential](/zh-TW/reference/tools/xtf/xtfapi/functions/xtfremovecredential-xtfapi-xbox-windows-m) 移除認證。使用 [XtfGetCredentialInfoList](/zh-TW/reference/tools/xtf/xtfapi/functions/xtfgetcredentialinfolist-xtfapi-xbox-windows-m)、[XtfGetCredentialInfoCount](/zh-TW/reference/tools/xtf/xtfapi/functions/xtfgetcredentialinfocount-xtfapi-xbox-windows-m)、[XtfGetCredentialServerName](/zh-TW/reference/tools/xtf/xtfapi/functions/xtfgetcredentialtargetname-xtfapi-xbox-windows-m) 和 [XtfGetCredentialUserName](/zh-TW/reference/tools/xtf/xtfapi/functions/xtfgetcredentialusername-xtfapi-xbox-windows-m) 列舉目前儲存的認證清單。使用 [XtfCloseCredentialInfoList](/zh-TW/reference/tools/xtf/xtfapi/functions/xtfclosecredentialinfo-xtfapi-xbox-windows-m) 釋放 [XtfGetCredentialInfoList](/zh-TW/reference/tools/xtf/xtfapi/functions/xtfgetcredentialinfolist-xtfapi-xbox-windows-m) 所傳回的 `XtfNetworkCredentials`。

<Note>
  [XtfGetCredentialInfoList](/zh-TW/reference/tools/xtf/xtfapi/functions/xtfgetcredentialinfolist-xtfapi-xbox-windows-m) 會從主機擷取所有資訊。[XtfGetCredentialServerName](/zh-TW/reference/tools/xtf/xtfapi/functions/xtfgetcredentialtargetname-xtfapi-xbox-windows-m) 和 [XtfGetCredentialUserName](/zh-TW/reference/tools/xtf/xtfapi/functions/xtfgetcredentialusername-xtfapi-xbox-windows-m) 只是逐一查看所擷取的資訊。
</Note>

<Note>
  擷取所需的值之後，請使用 [XtfCloseCredentialInfoList](/zh-TW/reference/tools/xtf/xtfapi/functions/xtfclosecredentialinfo-xtfapi-xbox-windows-m) 釋放與傳回的 XtfNetworkCredentials 物件相關聯的資源。
</Note>

<a id="ID4ETC" />

```cpp theme={null}
HRESULT               hr                = S_OK;
PCWSTR                consoleAddress    = L"190.167.10.182";
XtfNetworkCredentials credentialInfo    = nullptr;
UINT32                count             = 0;
PWSTR                 pServerNameBuffer = nullptr;
PWSTR                 pUserNameBuffer   = nullptr;
UINT32                bufferSize        = 0;

hr = XtfAddCredential(consoleAddress, L"devpc001", L"devpc001\\test", L"test");
if (FAILED(hr))
{
    wprintf(L"\n\n*** XtfAddCredential failed 0x%x", hr);
    return hr;
}

hr = XtfAddCredential(consoleAddress, L"devpc002", L"devpc002\\test1", L"test1");
if (FAILED(hr))
{
    wprintf(L"\n\n*** XtfAddCredential failed 0x%x", hr);
    return hr;
}

hr = XtfGetCredentialInfoList(consoleAddress, &credentialInfo);
if (FAILED(hr))
{
    wprintf(L"\n\n*** XtfGetCredentialInfoList failed 0x%x", hr);
    return hr;
}

hr = XtfGetCredentialInfoCount(credentialInfo, &count);
if (FAILED(hr))
{
    wprintf(L"\n\n*** XtfGetCredentialInfoCount failed 0x%x", hr);
    return hr;
}

wprintf(L"\n\n*** List of Users:");
wprintf(L"\n\t*** Number of users: %d", count);


for (UINT32 i=0; i < count ; i++)
{
    bufferSize=0;
    hr = XtfGetCredentialServerName(credentialInfo, i, nullptr, &bufferSize);
    if (hr != HRESULT_FROM_WIN32(ERROR_MORE_DATA))
    {
        wprintf(L"\n\n*** XtfGetCredentialServerName failed 0x%x", hr);
        return hr;
    }

    pServerNameBuffer = new WCHAR[bufferSize];

    hr = XtfGetCredentialServerName(credentialInfo, i, pServerNameBuffer, &bufferSize);
    if (FAILED(hr))
    {
        wprintf(L"\n\n*** XtfGetCredentialServerName failed 0x%x", hr);
        return hr;
    }

    bufferSize=0;
    hr = XtfGetCredentialUserName(credentialInfo, i, nullptr, &bufferSize);
    if (hr != HRESULT_FROM_WIN32(ERROR_MORE_DATA))
    {
        wprintf(L"\n\n*** XtfGetCredentialUserName failed 0x%x", hr);
        return hr;
    }

    pUserNameBuffer = new WCHAR[bufferSize];

    hr = XtfGetCredentialUserName(credentialInfo, i, pUserNameBuffer, &bufferSize);
    if (FAILED(hr))
    {
        wprintf(L"\n\n*** XtfGetCredentialUserName failed 0x%x", hr);
        return hr;
    }

    wprintf(L"\n\t Server: %ls, User: %ls", pServerNameBuffer, pUserNameBuffer);
    delete[] pServerNameBuffer;
    delete[] pUserNameBuffer;
}

XtfCloseCredentialInfoList(credentialInfo);

hr = XtfRemoveCredential(consoleAddress, L"devpc001");
if (FAILED(hr))
{
    wprintf(L"\n\n*** XtfRemoveCredential failed 0x%x", hr);
    return hr;
}

hr = XtfRemoveCredential(consoleAddress, L"devpc002");
if (FAILED(hr))
{
    wprintf(L"\n\n*** XtfRemoveCredential failed 0x%x", hr);
    return hr;
}

hr = XtfGetCredentialInfoList(consoleAddress, &credentialInfo);
if (FAILED(hr))
{
    wprintf(L"\n\n*** XtfGetCredentialInfoList failed 0x%x", hr);
    return hr;
}

hr = XtfGetCredentialInfoCount(credentialInfo, &count);
if (FAILED(hr))
{
    wprintf(L"\n\n*** XtfGetCredentialInfoCount failed 0x%x", hr);
    return hr;
}

wprintf(L"\n\n*** Number of users: %d", count);
XtfCloseCredentialInfoList(credentialInfo);

wprintf(L"\n\n");
return hr;  
```

## 需求

**標頭：** xtfapi.h

**程式庫：** XtfApi.lib

**支援的平台：** Windows (適用於 XBOX 主機工具)

## 另請參閱

[從 PC 執行部署 (NDA 主題)](/zh-TW/home/setup-install/concepts/deployment)<br />[XTF 傳輸錯誤 (NDA 主題)](/zh-TW/tools/tools-console/commandlinetools/xtf-transport-errors)<br />[其他 Xtf API](/zh-TW/reference/tools/xtf/xtfapi/atoc-xtfapi)


## Related topics

- [XtfCloseCredentialInfoList](/zh-TW/reference/tools/xtf/xtfapi/functions/xtfclosecredentialinfo-xtfapi-xbox-windows-m.md)
- [XtfRemoveCredential](/zh-TW/reference/tools/xtf/xtfapi/functions/xtfremovecredential-xtfapi-xbox-windows-m.md)
- [XtfGetCredentialInfoCount](/zh-TW/reference/tools/xtf/xtfapi/functions/xtfgetcredentialinfocount-xtfapi-xbox-windows-m.md)
- [XtfAddCredential](/zh-TW/reference/tools/xtf/xtfapi/functions/xtfaddcredential-xtfapi-xbox-windows-m.md)
- [XtfGetCredentialServerName](/zh-TW/reference/tools/xtf/xtfapi/functions/xtfgetcredentialtargetname-xtfapi-xbox-windows-m.md)
