File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -867,5 +867,23 @@ internal static FILE_TYPE GetFileType(SafeHandle hFile)
867867 ? throw ExceptionUtilities . GetExceptionForLastWin32Error ( ( WIN32_ERROR ) lastWin32Error )
868868 : res ;
869869 }
870+
871+ /// <summary>
872+ /// Retrieves information about the system's current usage of both physical and virtual memory.
873+ /// </summary>
874+ /// <remarks>This method wraps the native GlobalMemoryStatusEx function. The output parameter must
875+ /// not be used until the method returns successfully. If the call fails, an exception is thrown.</remarks>
876+ /// <param name="lpBuffer">When this method returns, contains a structure that receives information about current memory availability.
877+ /// The structure's fields are populated with memory status data.</param>
878+ /// <returns>true if the memory status information was successfully retrieved; otherwise, false.</returns>
879+ internal static BOOL GlobalMemoryStatusEx ( out MEMORYSTATUSEX lpBuffer )
880+ {
881+ lpBuffer = new MEMORYSTATUSEX
882+ {
883+ dwLength = ( uint ) Marshal . SizeOf < MEMORYSTATUSEX > ( )
884+ } ;
885+ BOOL res = PInvoke . GlobalMemoryStatusEx ( ref lpBuffer ) ;
886+ return ! res ? throw ExceptionUtilities . GetExceptionForLastWin32Error ( ) : res ;
887+ }
870888 }
871889}
Original file line number Diff line number Diff line change @@ -61,6 +61,7 @@ GetTokenInformation
6161GetWindowText
6262GetWindowTextLength
6363GetWindowThreadProcessId
64+ GlobalMemoryStatusEx
6465HIWORD
6566HKEY_CLASSES_ROOT
6667HKEY_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{
@@ -103,5 +104,15 @@ public static DomainStatus GetDomainStatus()
103104 return new ( ( NETSETUP_JOIN_STATUS ) bufferType , nameBuffer . ToStringUni ( ) ) ;
104105 }
105106 }
107+
108+ /// <summary>
109+ /// Retrieves the total amount of physical memory installed on the system, in bytes.
110+ /// </summary>
111+ /// <returns>The total physical memory, in bytes, available on the system.</returns>
112+ public static ulong GetTotalSystemMemory ( )
113+ {
114+ _ = Kernel32 . GlobalMemoryStatusEx ( out MEMORYSTATUSEX lpBuffer ) ;
115+ return lpBuffer . ullTotalPhys ;
116+ }
106117 }
107118}
You can’t perform that action at this time.
0 commit comments