/// <summary> /// The NetrShareEnum method retrieves information about each shared resource on a server. /// </summary> /// <param name="serverName">A string that identifies the server. If this parameter is NULL, the local computer is used.</param> /// <param name="infoStruct">A SHARE_ENUM_STRUCT structure. The SHARE_ENUM_STRUCT structure has a Level member /// that specifies the type of structure to return in the ShareInfo member.</param> /// <param name="PreferedMaximumLength">Specifies the preferred maximum length, in bytes, of the returned data. /// If the specified value is MAX_PREFERRED_LENGTH, the method MUST attempt to return all entries.</param> /// <param name="TotalEntries">The total number of entries that could have been enumerated if the buffer had been big enough to hold all the entries.</param> /// <param name="ResumeHandle">A pointer to a value that contains a handle, which is used to continue an existing share search in ShareList. /// handle MUST be zero on the first call and remain unchanged for subsequent calls. If the ResumeHandle parameter is NULL, no resume handle MUST be stored. /// If this parameter is not NULL and the method returns ERROR_MORE_DATA, this parameter receives a nonzero value that can be passed in subsequent /// calls to this method to continue with the enumeration in ShareList. If this parameter is NULL or points to 0x00000000, the enumeration starts from the beginning of the ShareList. /// </param> /// <returns>The method returns 0x00000000 (NERR_Success) to indicate success; otherwise, it returns a nonzero error code.</returns> public uint NetrShareEnum( string serverName, ref SHARE_ENUM_STRUCT infoStruct, uint PreferedMaximumLength, out uint?TotalEntries, ref uint?ResumeHandle) { /* NET_API_STATUS NetrShareEnum( * [in, string, unique] SRVSVC_HANDLE ServerName, * [in, out] LPSHARE_ENUM_STRUCT InfoStruct, * [in] DWORD PreferedMaximumLength, * [out] DWORD* TotalEntries, * [in, out, unique] DWORD* ResumeHandle * ); */ Int3264[] paramList; TotalEntries = 0; uint retVal = 0; using (SafeIntPtr pServerName = Marshal.StringToHGlobalUni(serverName), pInfoStruct = TypeMarshal.ToIntPtr(infoStruct), pResumeHandle = TypeMarshal.ToIntPtr(ResumeHandle)) { paramList = new Int3264[] { pServerName, pInfoStruct, PreferedMaximumLength, IntPtr.Zero, // out value pResumeHandle, IntPtr.Zero // return value }; using (RpceInt3264Collection outParamList = RpceCall(paramList, (ushort)SRVS_OPNUM.NetrShareEnum)) { retVal = outParamList[paramList.Length - 1].ToUInt32(); if (retVal == (uint)Win32ErrorCode_32.ERROR_SUCCESS) { infoStruct = TypeMarshal.ToStruct <SHARE_ENUM_STRUCT>(outParamList[1].ToIntPtr()); TotalEntries = TypeMarshal.ToNullableStruct <uint>(outParamList[3]); ResumeHandle = TypeMarshal.ToNullableStruct <uint>(outParamList[4]); } } } return(retVal); }
/// <summary> /// The NetrShareEnum method retrieves information about each shared resource on a server. /// </summary> /// <param name="serverName">A string that identifies the server. If this parameter is NULL, the local computer is used.</param> /// <param name="infoStruct">A SHARE_ENUM_STRUCT structure. The SHARE_ENUM_STRUCT structure has a Level member /// that specifies the type of structure to return in the ShareInfo member.</param> /// <param name="PreferedMaximumLength">Specifies the preferred maximum length, in bytes, of the returned data. /// If the specified value is MAX_PREFERRED_LENGTH, the method MUST attempt to return all entries.</param> /// <param name="TotalEntries">The total number of entries that could have been enumerated if the buffer had been big enough to hold all the entries.</param> /// <param name="ResumeHandle">A pointer to a value that contains a handle, which is used to continue an existing share search in ShareList. /// handle MUST be zero on the first call and remain unchanged for subsequent calls. If the ResumeHandle parameter is NULL, no resume handle MUST be stored. /// If this parameter is not NULL and the method returns ERROR_MORE_DATA, this parameter receives a nonzero value that can be passed in subsequent /// calls to this method to continue with the enumeration in ShareList. If this parameter is NULL or points to 0x00000000, the enumeration starts from the beginning of the ShareList. /// </param> /// <returns>The method returns 0x00000000 (NERR_Success) to indicate success; otherwise, it returns a nonzero error code.</returns> public uint NetrShareEnum( string serverName, ref SHARE_ENUM_STRUCT infoStruct, uint PreferedMaximumLength, out uint? TotalEntries, ref uint? ResumeHandle) { /* NET_API_STATUS NetrShareEnum( [in, string, unique] SRVSVC_HANDLE ServerName, [in, out] LPSHARE_ENUM_STRUCT InfoStruct, [in] DWORD PreferedMaximumLength, [out] DWORD* TotalEntries, [in, out, unique] DWORD* ResumeHandle ); */ Int3264[] paramList; TotalEntries = 0; uint retVal = 0; using (SafeIntPtr pServerName = Marshal.StringToHGlobalUni(serverName), pInfoStruct = TypeMarshal.ToIntPtr(infoStruct), pResumeHandle = TypeMarshal.ToIntPtr(ResumeHandle)) { paramList = new Int3264[]{ pServerName, pInfoStruct, PreferedMaximumLength, IntPtr.Zero, // out value pResumeHandle, IntPtr.Zero // return value }; using (RpceInt3264Collection outParamList = RpceCall(paramList, (ushort)SRVS_OPNUM.NetrShareEnum)) { retVal = outParamList[paramList.Length - 1].ToUInt32(); if (retVal == (uint)Win32ErrorCode_32.ERROR_SUCCESS) { infoStruct = TypeMarshal.ToStruct<SHARE_ENUM_STRUCT>(outParamList[1].ToIntPtr()); TotalEntries = TypeMarshal.ToNullableStruct<uint>(outParamList[3]); ResumeHandle = TypeMarshal.ToNullableStruct<uint>(outParamList[4]); } } } return retVal; }