How get list of local network computers?

前端 未结 6 451
甜味超标
甜味超标 2020-12-01 04:47

I am trying to get a list of local network computers. I tried to use NetServerEnum and WNetOpenEnum API, but both API return error code 6118

6条回答
  •  北海茫月
    2020-12-01 05:19

    I found solution using interface IShellItem with CSIDL_NETWORK. I get all network PC.

    C++: use method IShellFolder::EnumObjects

    C#: you can use Gong Solutions Shell Library

    using System.Collections;
    using System.Collections.Generic;
    using GongSolutions.Shell;
    using GongSolutions.Shell.Interop;
    
        public sealed class ShellNetworkComputers : IEnumerable
        {
            public IEnumerator GetEnumerator()
            {
                ShellItem folder = new ShellItem((Environment.SpecialFolder)CSIDL.NETWORK);
                IEnumerator e = folder.GetEnumerator(SHCONTF.FOLDERS);
    
                while (e.MoveNext())
                {
                    Debug.Print(e.Current.ParsingName);
                    yield return e.Current.ParsingName;
                }
            }
    
            IEnumerator IEnumerable.GetEnumerator()
            {
                return GetEnumerator();
            }
        }
    

提交回复
热议问题