private HostShareInfo[] GetHostShareInfo(string server) { // gets a share info object when given a host. List <HostShareInfo> shareInfos = new List <HostShareInfo>(); int entriesread = 0; int totalentries = 0; int resumeHandle = 0; int nStructSize = Marshal.SizeOf(typeof(HostShareInfo)); IntPtr bufPtr = IntPtr.Zero; int ret = NetShareEnum(new StringBuilder(server), 1, ref bufPtr, MaxPreferredLength, ref entriesread, ref totalentries, ref resumeHandle); if (ret == NerrSuccess) { IntPtr currentPtr = bufPtr; for (int i = 0; i < entriesread; i++) { HostShareInfo shi1 = (HostShareInfo)Marshal.PtrToStructure(currentPtr, typeof(HostShareInfo)); shareInfos.Add(shi1); currentPtr += nStructSize; } NetApiBufferFree(bufPtr); return(shareInfos.ToArray()); } shareInfos.Add(new HostShareInfo("ERROR=" + ret, 10, string.Empty)); return(shareInfos.ToArray()); }
private string GetShareName(HostShareInfo hostShareInfo, string computer) { // takes a HostShareInfo object and a computer name and turns it into a usable path. // first we want to throw away any errored out ones. string[] errors = { "ERROR=53", "ERROR=5" }; if (errors.Contains(hostShareInfo.shi1_netname)) { //Mq.Trace(hostShareInfo.shi1_netname + " on " + computer + //", but this is usually no cause for alarm."); return(null); } return($"\\\\{computer}\\{hostShareInfo.shi1_netname}"); }