Click here to Skip to main content
15,890,690 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to get the computers in my workgroup using Shell

C++
HRESULT hr = S_OK;
ULONG celtFetched;
LPITEMIDLIST pidlItems = NULL;
LPITEMIDLIST netItemIdLst = NULL;
IShellFolder* pFolder = NULL;
IEnumIDList* pEnumIds = NULL;
IShellFolder* pDesktopFolder = NULL;
LPITEMIDLIST full_pid;

hr = SHGetMalloc(&pMalloc);
hr = SHGetDesktopFolder(&pDesktopFolder);
hr = SHGetSpecialFolderLocation(NULL, CSIDL_COMPUTERSNEARME, &netItemIdLst);
hr = pDesktopFolder->BindToObject(netItemIdLst, NULL, 
                                  IID_IShellFolder, (void **)&pFolder);

if(SUCCEEDED(hr))
{
  hr = pFolder->EnumObjects(NULL, SHCONTF_NONFOLDERS, &pEnumIds);

  if(SUCCEEDED(hr))
  {
    STRRET strDisplayName;
    while((hr = pEnumIds->Next(1, &pidlItems, &celtFetched)) == S_OK && celtFetched > 0)
    {
      hr = pFolder->GetDisplayNameOf(pidlItems, SHGDN_NORMAL, &strDisplayName);
      if(SUCCEEDED(hr))
      {
        wprintf(L"%s\n", strDisplayName.pOleStr);
      }
    }
  }
}

But this returns the Computers, Media Devices, and Streaming Devices (is that it name?). Like say, a computer is called OSOFEM on my workgroup... STRRET::pOleStr returns strings OSOFEM (which is the computer), OSOFEM (I think streaming device), and OSOFEM:example@email.com: (which is the Windows Media Player).

My question is how can I distinguish which is the Computer? Of course, there names can't be used because two exactly the same name will always be returned...
Posted

1 solution

 
Share this answer
 
Comments
Oso Oluwafemi Ebenezer 12-Jul-13 7:06am    
thanks for your response. The third parameter of GetattributesOf is SFGAOF *rgfInOut which will hold the SFGAO value of the object. Which of these values shows that the object is a Computer as many of these are showing what you can do with the object and not what the object is.
KarstenK 12-Jul-13 7:10am    
such details should be read in the msdn...

i am no guru for that
Oso Oluwafemi Ebenezer 12-Jul-13 7:25am    
No such details was provided, just the list. Thanks anyway!
KarstenK 12-Jul-13 8:02am    
somehow you got to try your luck in sniffing in the structures or calling approbiate methods on the items.

look at this article from MSDN:

http://msdn.microsoft.com/en-us/library/windows/desktop/bb773321(v=vs.85).aspx
http://msdn.microsoft.com/en-us/library/windows/desktop/bb759800(v=vs.85).aspx

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900