locked
Searching for items in Windows 10 x86 does not find items RRS feed

  • Question

  • Hello,

    On Windows 10 x64 for the Services window (services.msc), I can find list items from list (SysListView32).
    But for Windows 10 x86 - no.

    I used FindAll and TreeWalker to both cases.

    How can I make it work for Windows 10 x86?


    • Edited by folkwulf Tuesday, April 28, 2020 7:22 PM Clarification
    Tuesday, April 28, 2020 7:21 PM

Answers

  • Hello.

    I test the following code in a Win32 C++ console application and run the application as administrator, it can find all items in services.msc (list items) on both Windows 10 x64 and x86 machine. So I can't reproduce this issue. Could you have a try to see if my demo work for you?

    #include <iostream>
    #include <UIAutomation.h>
    
    IUIAutomation *pClientUIA;
    IUIAutomationElement *pRootElement;
    
    void ListDescendants(IUIAutomationElement* pParent, int indent)
    {
    	HRESULT hr;
    
    	if (pParent == NULL)
    		return;
    
    	IUIAutomationTreeWalker* pControlWalker = NULL;
    	IUIAutomationElement* pNode = NULL;
    
    	pClientUIA->get_ControlViewWalker(&pControlWalker);
    	if (pControlWalker == NULL)
    		goto cleanup;
    
    	pControlWalker->GetFirstChildElement(pParent, &pNode);
    	if (pNode == NULL)
    		goto cleanup;
    
    	while (pNode)
    	{
    		BSTR desc;
    		pNode->get_CurrentLocalizedControlType(&desc);
    		for (int x = 0; x <= indent; x++)
    		{
    			std::wcout << L"   ";
    		}
    		std::wcout << desc << L"\n";
    
    		hr = pNode->get_CurrentName(&desc);
    		if (S_OK != hr)
    		{
    			printf("CreatePropertyCondition error: %d\n", GetLastError());
    		}
    		wprintf(L"Control Name: %s\n", desc);
    		hr = pNode->get_CurrentClassName(&desc);
    		if (S_OK != hr)
    		{
    			printf("CreatePropertyCondition error: %d\n", GetLastError());
    		}
    		wprintf(L"Class Name: %s\n", desc);
    
    		SysFreeString(desc);
    
    		ListDescendants(pNode, indent + 1);
    		IUIAutomationElement* pNext;
    		pControlWalker->GetNextSiblingElement(pNode, &pNext);
    		pNode->Release();
    		pNode = pNext;
    	}
    
    cleanup:
    	if (pControlWalker != NULL)
    		pControlWalker->Release();
    
    	if (pNode != NULL)
    		pNode->Release();
    
    	return;
    }
    
    int main()
    {
    	HRESULT hr = CoInitializeEx(NULL, COINITBASE_MULTITHREADED | COINIT_DISABLE_OLE1DDE);
    	if (S_OK != hr)
    	{
    		printf("CoInitializeEx error: %d\n", GetLastError());
    		return 1;
    	}
    
    	hr = CoCreateInstance(CLSID_CUIAutomation, NULL, CLSCTX_INPROC_SERVER, IID_IUIAutomation,reinterpret_cast<void**>(&pClientUIA));
    	if (S_OK != hr)
    	{
    		printf("CoCreateInstance error: %d\n", GetLastError());
    		return 1;
    	}
    
    	HWND hwnd = FindWindow(NULL, L"Services");
    	if (hwnd == NULL)
    	{
    		printf("FindWindow error: %d\n", GetLastError());
    		return 1;
    	}		
    
    	hr = pClientUIA->ElementFromHandle(hwnd, &pRootElement);
    	if (S_OK != hr)
    	{
    		printf("ElementFromHandle error: %d\n", GetLastError());
    		return 1;
    	}
    	BSTR name;
    	hr = pRootElement->get_CurrentClassName(&name);
    	if (S_OK != hr)
    	{
    		printf("get_CurrentClassName error: %d\n", GetLastError());
    		return 1;
    	}
    	wprintf(L"Class Name: %s\n", name);
    
    
    	ListDescendants(pRootElement, 0);
    
    	getchar();
    
    	return 1;
    }

    Please let me know if it helps.

    Best regards,

    Rita


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Wednesday, April 29, 2020 7:58 AM

All replies

  • Hello.

    I test the following code in a Win32 C++ console application and run the application as administrator, it can find all items in services.msc (list items) on both Windows 10 x64 and x86 machine. So I can't reproduce this issue. Could you have a try to see if my demo work for you?

    #include <iostream>
    #include <UIAutomation.h>
    
    IUIAutomation *pClientUIA;
    IUIAutomationElement *pRootElement;
    
    void ListDescendants(IUIAutomationElement* pParent, int indent)
    {
    	HRESULT hr;
    
    	if (pParent == NULL)
    		return;
    
    	IUIAutomationTreeWalker* pControlWalker = NULL;
    	IUIAutomationElement* pNode = NULL;
    
    	pClientUIA->get_ControlViewWalker(&pControlWalker);
    	if (pControlWalker == NULL)
    		goto cleanup;
    
    	pControlWalker->GetFirstChildElement(pParent, &pNode);
    	if (pNode == NULL)
    		goto cleanup;
    
    	while (pNode)
    	{
    		BSTR desc;
    		pNode->get_CurrentLocalizedControlType(&desc);
    		for (int x = 0; x <= indent; x++)
    		{
    			std::wcout << L"   ";
    		}
    		std::wcout << desc << L"\n";
    
    		hr = pNode->get_CurrentName(&desc);
    		if (S_OK != hr)
    		{
    			printf("CreatePropertyCondition error: %d\n", GetLastError());
    		}
    		wprintf(L"Control Name: %s\n", desc);
    		hr = pNode->get_CurrentClassName(&desc);
    		if (S_OK != hr)
    		{
    			printf("CreatePropertyCondition error: %d\n", GetLastError());
    		}
    		wprintf(L"Class Name: %s\n", desc);
    
    		SysFreeString(desc);
    
    		ListDescendants(pNode, indent + 1);
    		IUIAutomationElement* pNext;
    		pControlWalker->GetNextSiblingElement(pNode, &pNext);
    		pNode->Release();
    		pNode = pNext;
    	}
    
    cleanup:
    	if (pControlWalker != NULL)
    		pControlWalker->Release();
    
    	if (pNode != NULL)
    		pNode->Release();
    
    	return;
    }
    
    int main()
    {
    	HRESULT hr = CoInitializeEx(NULL, COINITBASE_MULTITHREADED | COINIT_DISABLE_OLE1DDE);
    	if (S_OK != hr)
    	{
    		printf("CoInitializeEx error: %d\n", GetLastError());
    		return 1;
    	}
    
    	hr = CoCreateInstance(CLSID_CUIAutomation, NULL, CLSCTX_INPROC_SERVER, IID_IUIAutomation,reinterpret_cast<void**>(&pClientUIA));
    	if (S_OK != hr)
    	{
    		printf("CoCreateInstance error: %d\n", GetLastError());
    		return 1;
    	}
    
    	HWND hwnd = FindWindow(NULL, L"Services");
    	if (hwnd == NULL)
    	{
    		printf("FindWindow error: %d\n", GetLastError());
    		return 1;
    	}		
    
    	hr = pClientUIA->ElementFromHandle(hwnd, &pRootElement);
    	if (S_OK != hr)
    	{
    		printf("ElementFromHandle error: %d\n", GetLastError());
    		return 1;
    	}
    	BSTR name;
    	hr = pRootElement->get_CurrentClassName(&name);
    	if (S_OK != hr)
    	{
    		printf("get_CurrentClassName error: %d\n", GetLastError());
    		return 1;
    	}
    	wprintf(L"Class Name: %s\n", name);
    
    
    	ListDescendants(pRootElement, 0);
    
    	getchar();
    
    	return 1;
    }

    Please let me know if it helps.

    Best regards,

    Rita


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Wednesday, April 29, 2020 7:58 AM
  • Thanks, Rita Han.

    Issue was resolved by run the application as administrator.


    • Edited by folkwulf Tuesday, May 12, 2020 3:32 PM
    Tuesday, May 12, 2020 3:31 PM