File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -944,5 +944,23 @@ internal static FILE_FLAGS_AND_ATTRIBUTES GetFileAttributes(string lpFileName)
944944 uint res = PInvoke . GetFileAttributes ( lpFileName ) ;
945945 return res == PInvoke . INVALID_FILE_ATTRIBUTES ? throw ExceptionUtilities . GetExceptionForLastWin32Error ( ) : ( FILE_FLAGS_AND_ATTRIBUTES ) res ;
946946 }
947+
948+ /// <summary>
949+ /// Retrieves information about the system's current usage of both physical and virtual memory.
950+ /// </summary>
951+ /// <remarks>This method wraps the native GlobalMemoryStatusEx function. The output parameter must
952+ /// not be used until the method returns successfully. If the call fails, an exception is thrown.</remarks>
953+ /// <param name="lpBuffer">When this method returns, contains a structure that receives information about current memory availability.
954+ /// The structure's fields are populated with memory status data.</param>
955+ /// <returns>true if the memory status information was successfully retrieved; otherwise, false.</returns>
956+ internal static BOOL GlobalMemoryStatusEx ( out MEMORYSTATUSEX lpBuffer )
957+ {
958+ lpBuffer = new MEMORYSTATUSEX
959+ {
960+ dwLength = ( uint ) Marshal . SizeOf < MEMORYSTATUSEX > ( )
961+ } ;
962+ BOOL res = PInvoke . GlobalMemoryStatusEx ( ref lpBuffer ) ;
963+ return ! res ? throw ExceptionUtilities . GetExceptionForLastWin32Error ( ) : res ;
964+ }
947965 }
948966}
Original file line number Diff line number Diff line change @@ -65,6 +65,7 @@ GetTokenInformation
6565GetWindowText
6666GetWindowTextLength
6767GetWindowThreadProcessId
68+ GlobalMemoryStatusEx
6869HIWORD
6970HKEY_CLASSES_ROOT
7071HKEY_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