SOLUTION
I change my code accord to http://www.pinvoke.net/default.aspx/netapi32/netserverenum.html
and all works well
- ยก using SERVER_INFO_101 !
I have the same isue with this code
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);
}
}
in line
tmpBuffer = new IntPtr((int)buffer + (i * sizeofINFO));
the method crash....