> ## 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.

# XtfGetCredentialUserName

> XtfGetCredentialUserName

# XtfGetCredentialUserName

获取由 [XtfGetCredentialInfoList](/reference/tools/xtf/xtfapi/functions/xtfgetcredentialinfolist-xtfapi-xbox-windows-m) 返回的 XtfNetworkCredentials 对象中指定索引处凭据的用户名部分。

<a id="syntaxSection" />

## 语法

```cpp theme={null}
HRESULT XtfGetCredentialUserName(
         XtfNetworkCredentials credentialInfo,
         UINT32 credentialIndex,
         PWSTR userName,
         UINT32 *userNameLength
)  
```

<a id="ID4EK" />

### 参数

*credentialInfo*<br />类型：XtfNetworkCredentials

\[in] 通过调用 [XtfGetCredentialInfoList](/reference/tools/xtf/xtfapi/functions/xtfgetcredentialinfolist-xtfapi-xbox-windows-m) 创建的 XtfNetworkCredentials 对象。

*credentialIndex*<br />类型：UINT32

\[in] **credentialInfo** 对象中 **userName** 的索引。

*userName*<br />类型：PWSTR

\[out] **credentialInfo** 对象中给定索引处的用户名。

*userNameLength*<br />类型：UINT32 \*

\[in, out] **userName** 缓冲区的长度（以 WCHAR 为单位）。

<a id="ID4ER" />

### 返回值

类型：HRESULT

成功时返回 **S\_OK**。如果 **userName** 空间不够，则返回 HRESULT\_FROM\_WIN32(ERROR\_MORE\_DATA)。所需的缓冲区长度在 **userNameLength** 中返回。

<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。

有关如何使用此 API 的示例，请参阅 [XtfGetCredentialInfoList](/reference/tools/xtf/xtfapi/functions/xtfgetcredentialinfolist-xtfapi-xbox-windows-m)。

## 要求

**头文件：** 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

- [XtfGetCredentialInfoList](/zh-CN/reference/tools/xtf/xtfapi/functions/xtfgetcredentialinfolist-xtfapi-xbox-windows-m.md)
- [XtfGetCredentialServerName](/zh-CN/reference/tools/xtf/xtfapi/functions/xtfgetcredentialtargetname-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)
- [XtfCloseCredentialInfoList](/zh-CN/reference/tools/xtf/xtfapi/functions/xtfclosecredentialinfo-xtfapi-xbox-windows-m.md)
