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

# XtfGetConsoleInfoList

> XtfGetConsoleInfoList

# XtfGetConsoleInfoList

傳回包含主機相關資訊的 `XtfConsoleInfo` 物件。

<a id="syntaxSection" />

## 語法

```cpp theme={null}
HRESULT XtfGetConsoleInfoList(
         PCWSTR address,
         XtfConsoleInfo *hConsoleInfo
)  
```

<a id="parametersSection" />

### 參數

*address*\
類型：PCWSTR

\[in] 主機的位址。

*hConsoleInfo*\
類型：XtfConsoleInfo\*

\[out] 與 [XtfGetConsoleFieldValue](/zh-TW/reference/tools/xtf/xtfapi/functions/xtfgetconsolefieldvalue-xbox-microsoft-m) 函式搭配使用以擷取主機相關資訊的指標。

<a id="retvalSection" />

### 傳回值

類型：HRESULT

如果函式成功，且可以使用 [XtfGetConsoleFieldValue](/zh-TW/reference/tools/xtf/xtfapi/functions/xtfgetconsolefieldvalue-xbox-microsoft-m) 從 **hConsoleInfo** 擷取值，則傳回 `S_OK`；否則傳回 HRESULT 錯誤碼。

<a id="remarksSection" />

## 備註

若要擷取主機的相關資訊，請先使用此函式取得 `XtfConsoleInfo` 指標，然後使用 [XtfGetConsoleFieldValue](/zh-TW/reference/tools/xtf/xtfapi/functions/xtfgetconsolefieldvalue-xbox-microsoft-m) 從該指標擷取主機的相關資訊。擷取所需的資訊之後，請使用 [XtfCloseConsoleInfoList](/zh-TW/reference/tools/xtf/xtfapi/functions/xtfcloseconsoleinfolist-xbox-microsoft-m) 釋放與傳回之 `XtfConsoleInfo` 指標相關聯的資源。

<Note>`XtfGetConsoleInfoList` 會從主機擷取所有資訊，並提供指向該資訊的指標。[XtfGetConsoleFieldValue](/zh-TW/reference/tools/xtf/xtfapi/functions/xtfgetconsolefieldvalue-xbox-microsoft-m) 只會逐一查看所擷取的資訊。您必須同時使用這兩個函式，才能擷取主機的相關資訊。</Note>

<Note>如果在此函式的 `address` 中指定的目標主機尚未佈建，則當 `field` 中指定 [XtfConsoleFieldId::DeviceID](/zh-TW/reference/tools/xtf/xtfapi/enums/xtfconsolefieldid-xbox-windows-t) 時，[XtfGetConsoleFieldValue](/zh-TW/reference/tools/xtf/xtfapi/functions/xtfgetconsolefieldvalue-xbox-microsoft-m) 函式會傳回空值。</Note>

下列程式碼範例示範如何同時使用 `XtfGetConsoleInfoList` 與 `XtfGetConsoleFieldValue` 函式來擷取開發主機的主機識別碼。

```cpp theme={null}
int wmain(int argc, wchar_t **argv)
{
  HRESULT             hr             = S_OK;
  PCWSTR              consoleAddress = L" 190.167.10.18";
  XtfConsoleInfo      hConsoleInfo   = nullptr;
  XtfConsoleFieldType fieldType      = XtfConsoleFieldType::FieldTypeUINT32;
  BYTE *              pValueBuffer   = nullptr;
  UINT32              bufferSize     = 0;

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

  hr = XtfGetConsoleFieldValue(hConsoleInfo, XtfConsoleFieldId::ConsoleId, &fieldType, nullptr, &bufferSize);
  if (hr != HRESULT_FROM_WIN32(ERROR_MORE_DATA))
  {
    XtfCloseConsoleInfoList(hConsoleInfo);
    wprintf(L"\n\n*** XtfGetConsoleFieldValue failed 0x%x", hr);
    return hr;
  }

  pValueBuffer = new BYTE[bufferSize];

  hr  = XtfGetConsoleFieldValue(hConsoleInfo, XtfConsoleFieldId::ConsoleId, &fieldType, pValueBuffer, &bufferSize);
  if (SUCCEEDED(hr))
  {
    PWCHAR consoleId = (PWCHAR)pValueBuffer;
    wprintf(L"\n\n*** Console ID is %s", consoleId);
  }
  else
  {
    wprintf(L"\n\n*** XtfGetConsoleFieldValue failed 0x%x", hr);
  }

  XtfCloseConsoleInfoList(hConsoleInfo);
  delete[] pValueBuffer;

  return hr;
}  
```

<a id="requirementsSection" />

## 需求

**標頭：** xtfapi.h

**程式庫：** XtfApi.lib

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

<a id="seealsoSection" />

## 另請參閱

[XtfConsoleControl](/zh-TW/reference/tools/xtf/xtfconsolecontrol/xtfconsolecontrol_members)\
[XBOX Tools Framework](/zh-TW/reference/tools/xtf/atoc-xbox-tools-framework)


## Related topics

- [XtfCloseConsoleInfoList](/zh-TW/reference/tools/xtf/xtfapi/functions/xtfcloseconsoleinfolist-xbox-microsoft-m.md)
- [XtfGetConsoleFieldValue](/zh-TW/reference/tools/xtf/xtfapi/functions/xtfgetconsolefieldvalue-xbox-microsoft-m.md)
- [XtfGetCredentialInfoList](/zh-TW/reference/tools/xtf/xtfapi/functions/xtfgetcredentialinfolist-xtfapi-xbox-windows-m.md)
- [XtfCloseCredentialInfoList](/zh-TW/reference/tools/xtf/xtfapi/functions/xtfclosecredentialinfo-xtfapi-xbox-windows-m.md)
- [XtfGetCredentialInfoCount](/zh-TW/reference/tools/xtf/xtfapi/functions/xtfgetcredentialinfocount-xtfapi-xbox-windows-m.md)
