> ## 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](/reference/tools/xtf/xtfapi/functions/xtfaddcredential-xtfapi-xbox-windows-m) 添加凭据。使用 [XtfRemoveCredential](/reference/tools/xtf/xtfapi/functions/xtfremovecredential-xtfapi-xbox-windows-m) 移除凭据。使用 [XtfGetCredentialInfoList](/reference/tools/xtf/xtfapi/functions/xtfgetcredentialinfolist-xtfapi-xbox-windows-m)、[XtfGetCredentialInfoCount](/reference/tools/xtf/xtfapi/functions/xtfgetcredentialinfocount-xtfapi-xbox-windows-m)、[XtfGetCredentialServerName](/reference/tools/xtf/xtfapi/functions/xtfgetcredentialtargetname-xtfapi-xbox-windows-m) 和 [XtfGetCredentialUserName](/reference/tools/xtf/xtfapi/functions/xtfgetcredentialusername-xtfapi-xbox-windows-m) 来枚举当前存储的凭据列表。使用 [XtfCloseCredentialInfoList](/reference/tools/xtf/xtfapi/functions/xtfclosecredentialinfo-xtfapi-xbox-windows-m) 释放由 [XtfGetCredentialInfoList](/reference/tools/xtf/xtfapi/functions/xtfgetcredentialinfolist-xtfapi-xbox-windows-m) 返回的 `XtfNetworkCredentials`。

<Note>
  [XtfGetCredentialInfoList](/reference/tools/xtf/xtfapi/functions/xtfgetcredentialinfolist-xtfapi-xbox-windows-m) 会从主机检索所有信息。[XtfGetCredentialServerName](/reference/tools/xtf/xtfapi/functions/xtfgetcredentialtargetname-xtfapi-xbox-windows-m) 和 [XtfGetCredentialUserName](/reference/tools/xtf/xtfapi/functions/xtfgetcredentialusername-xtfapi-xbox-windows-m) 只是遍历该已检索的信息。
</Note>

<Note>
  检索到所需的值后，使用 [XtfCloseCredentialInfoList](/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 主机工具）

## 另请参阅

[Run from PC Deployment (NDA 主题)](/home/setup-install/concepts/deployment)<br />[XTF 传输错误 (NDA 主题)](/tools/tools-console/commandlinetools/xtf-transport-errors)<br />[其他 Xtf API](/reference/tools/xtf/xtfapi/atoc-xtfapi)


## Related topics

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