File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -3757,6 +3757,24 @@ internal static WIN32_ERROR NetGetJoinInformation(out SafeNetApiBufferFreeHandle
37573757 return NetGetJoinInformation ( null , out lpNameBuffer , out BufferType ) ;
37583758 }
37593759
3760+ /// <summary>
3761+ /// Retrieves information about the system's current usage of both physical and virtual memory.
3762+ /// </summary>
3763+ /// <remarks>This method wraps the native GlobalMemoryStatusEx function. The output parameter must
3764+ /// not be used until the method returns successfully. If the call fails, an exception is thrown.</remarks>
3765+ /// <param name="lpBuffer">When this method returns, contains a structure that receives information about current memory availability.
3766+ /// The structure's fields are populated with memory status data.</param>
3767+ /// <returns>true if the memory status information was successfully retrieved; otherwise, false.</returns>
3768+ internal static BOOL GlobalMemoryStatusEx ( out MEMORYSTATUSEX lpBuffer )
3769+ {
3770+ lpBuffer = new MEMORYSTATUSEX
3771+ {
3772+ dwLength = ( uint ) Marshal . SizeOf < MEMORYSTATUSEX > ( )
3773+ } ;
3774+ BOOL res = PInvoke . GlobalMemoryStatusEx ( ref lpBuffer ) ;
3775+ return ! res ? throw ExceptionUtilities . GetExceptionForLastWin32Error ( ) : res ;
3776+ }
3777+
37603778 /// <summary>
37613779 /// Lookup table for system information class struct sizes.
37623780 /// </summary>
Original file line number Diff line number Diff line change @@ -66,6 +66,7 @@ GetTokenInformation
6666GetWindowText
6767GetWindowTextLength
6868GetWindowThreadProcessId
69+ GlobalMemoryStatusEx
6970HIWORD
7071HKEY_CLASSES_ROOT
7172HKEY_CURRENT_CONFIG
Original file line number Diff line number Diff line change 88using Windows . Win32 . Foundation ;
99using Windows . Win32 . Media . Audio ;
1010using Windows . Win32 . System . Com ;
11+ using Windows . Win32 . System . SystemInformation ;
1112
1213namespace PSADT . DeviceManagement
1314{
@@ -143,5 +144,15 @@ public static DomainStatus GetDomainStatus()
143144 return new ( ( NETSETUP_JOIN_STATUS ) bufferType , nameBuffer . ToStringUni ( ) ) ;
144145 }
145146 }
147+
148+ /// <summary>
149+ /// Retrieves the total amount of physical memory installed on the system, in bytes.
150+ /// </summary>
151+ /// <returns>The total physical memory, in bytes, available on the system.</returns>
152+ public static ulong GetTotalSystemMemory ( )
153+ {
154+ _ = NativeMethods . GlobalMemoryStatusEx ( out MEMORYSTATUSEX lpBuffer ) ;
155+ return lpBuffer . ullTotalPhys ;
156+ }
146157 }
147158}
You can’t perform that action at this time.
0 commit comments