2

我们有一个 .NET 应用程序,它通过 P/Invoke 使用 WNet API 来枚举 Windows 网络中的网络资源。该应用程序在 Vista 和 Windows 7 上完美运行,但在 Windows 8 中它没有发现任何东西。

我尝试调试它并且没有错误,它实际上在第一级找到了一些网络容器,但是在它们内部它什么也没找到,它总是返回零条目和“没有更多条目”代码。

Windows 8 上的 WNet API 是否存在任何已知问题?

谢谢,米海

4

1 回答 1

0

解决方案

我将代码更改为http://www.pinvoke.net/default.aspx/netapi32/netserverenum.html 并且一切正常

  • ¡ 使用 SERVER_INFO_101 !

我对这段代码有同样的问题

int ret = NetServerEnum(null, 100, ref buffer,
                    MAX_PREFERRED_LENGTH,
                    out entriesRead,
                    out totalEntries, SV_TYPE_WORKSTATION | SV_TYPE_SERVER | SV_TYPE_WINDOWS | SV_TYPE_NT, null, out 
                resHandle);
                //if the returned with a NERR_Success 
                //(C++ term), =0 for C#
                if (ret == 0)
                {
                    //loop through all SV_TYPE_WORKSTATION 
                    //and SV_TYPE_SERVER PC's
                    for (int i = 0; i < totalEntries; i++)
                    {
                        //get pointer to, Pointer to the 
                        //buffer that received the data from
                        //the call to NetServerEnum. 
                        //Must ensure to use correct size of 
                        //STRUCTURE to ensure correct 
                        //location in memory is pointed to
                        tmpBuffer = new IntPtr((int)buffer + (i * sizeofINFO));
                        //Have now got a pointer to the list 
                        //of SV_TYPE_WORKSTATION and 
                        //SV_TYPE_SERVER PC's, which is unmanaged memory
                        //Needs to Marshal data from an 
                        //unmanaged block of memory to a 
                        //managed object, again using 
                        //STRUCTURE to ensure the correct data
                        //is marshalled 
                        _SERVER_INFO_100 svrInfo = (_SERVER_INFO_100)Marshal.PtrToStructure(tmpBuffer, typeof(_SERVER_INFO_100));
                        //add the PC names to the ArrayList
                        networkComputers.Add(svrInfo.sv100_name);
                    }
                }

排队

                        tmpBuffer = new IntPtr((int)buffer + (i * sizeofINFO));

方法崩溃....

于 2014-03-11T13:50:59.567 回答