Jump to content

Detecting Total Physical Memory


Recommended Posts

Posted

Hello everyone,

As part of my WinPE 2.0 boot cd, I am launching an HTA which displays ip address information, mapped drive information and I would also like to display processor and total memory information. My purpose is to advise the technician building the computer if the memory is less than XXXmb, it does not meet minimum specs.

The HTA code works find on my tech workstation. However, once I use it on my boot cd with WinPE, I am unable to display any information about logical or physical memory. I am unable to even get a msgbox to display the amount of memory. The msgbox appears but is empty.

My code is currently as follows:

strComputer = "."
Set objwmiService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")

' Query processor properties
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_Processor", "WQL", _
wbemFlagReturnImmediately + wbemFlagForwardOnly)
For Each objItem In colItems
strProcessor = strProcessor & objItem.DeviceID & "/ " & Strip( objItem.Name ) & vbCrLf
strHtml3 = strProcessor
If objItem.MaxClockspeed =<929 Then
strHtml3 = strProcessor & "<Font color = Red>" & " May not meet minimum"
msgbox "Please verify processor speed meets minimum requirements"
End If
Next

'Detect Total Logical Memory
Set colItems = objWMIService.ExecQuery( "Select * From Win32_LogicalMemoryConfiguration" )
For Each objItem In colItems
strMemory = Int( ( objItem.TotalPhysicalMemory + 1023 ) / 1024 ) & " MB"
msgbox strMemory
strHtml4 = strMemory
If Int( ( objItem.TotalPhysicalMemory + 1023 ) / 1024 ) =<512 Then
strHtml4 = strMemory & "<Font color = Red>" & " May not meet minimum"
msgbox "Please verify total system memory meets minimum requirements"
End If
Next

Next

Thank you in advance for any insight as to why this could be happening...


Posted

Try using Win32_ComputerSystem.TotalPhysicalMemory. Scriptomatic v2 by the Microsoft Scripting Guys is a good tool for seeing all the available WMI classes and their values. Scriptomatic V2

Posted

Wrex....

Thank you for the help...I am not sure why it works now but it does...and sometimes that is what matters.

It is now reporting total MB...any suggestion as to how I can get it to report in MB or GB when necessary?

Posted

The data retrieved from WMI is static, you can't tell it to give it to you in a different value, so here's some pseudo code to do the conversion:


If valMemSize > 1073741824 Then ' If more than 1GB
arrMemSize = Split( (valMemSize / 1073741824),".") ' Ex. 1.5GB, arrMemSize(0) = 1, arrMemSize(1) = 5
strMemSize = arrMemSize(0) & "." & Left(arrMemSize(1),1) & "GB" ' Left(val,1) for 1 number right of decimal point
End If

Posted

Wrex,

Again, I wish I had your genius, this looks like it will work perfectly. I understand the static nature of the wmi data retrieval, just did know how to code the manipulation of the returned value....but thanks to people such as you, I am learning.

Thank you again

Posted

No problem. I've been up to my eyeballs in this stuff for weeks so I know what it can be like if you hit a wall. Lots of trial and error and visits with my good friend Google and MSFN. ;)

Posted

Funny how we all go through the same process trying to achieve similar results, each with our own little tweaks along the way. I never would have been able to make it this far without you and others assistance, and as you mentioned, MSFN and Google.

I have been searching for a post with content on minimizing the size of WinPE and decreasing the boot time....any suggestions?

Posted

You can find posts listing what files can be removed from PE, but everything I've read about reducing the image size has not gained much in the way of load time. The way I figure it, it's completely dependent on the speed of the PC being able to stream the files or WIM into RAM. If you boot it from CD, it depends on how fast the CD drive can stream and the PC can process the loading of the files into RAM. Same with a USB stick. You would think that reducing the size of data being loaded would reduce the load time, but that doesn't seem to be the case. However, if loading into RAM from a hard disk, it's lightning quick, presumably due to the speed of the drive.

I have a "preload" option in my system where the user can boot up the CD without a network connection, set whatever options necessary, then have the hard drive partitioned, formatted, and loaded with the bootable WIM copied to C: from the CD drive. The boot menu is then configured to load the WIM into RAM, so it's like booting the CD, but much faster. I did this because my automated process could potentially hit snags if required data can't be found through WMI and the user has to be prompted for it. This way, the boot time to the possible prompt is nowhere near what it would be from CD.

  • 2 weeks later...
Posted (edited)

Here is one more suggestion, it is what I use to check the memory of a device and if its too low, to create a pagefile.



Private Declare Sub GlobalMemoryStatus Lib "kernel32" (lpBuffer As MEMORYSTATUS)

Private Type MEMORYSTATUS
dwLength As Long
dwMemoryLoad As Long
dwTotalPhys As Long
dwAvailPhys As Long
dwTotalPageFile As Long
dwAvailPageFile As Long
dwTotalVirtual As Long
dwAvailVirtual As Long
End Type

Public Sub CheckMemory()

Dim MS As MEMORYSTATUS

MS.dwLength = Len(MS)
GlobalMemoryStatus MS
lPhysicalRAM = MS.dwTotalPhys / 1024 ^ 2

If lPhysicalRAM < 320 Then

If FolderExists("I:\") Then
ShellAndWait "WPEUTIL CreatePageFile /path=I:\pagefile.sys /size=256", vbHide
If Not FileExists("I:\pagefile.sys") Then
ShellAndWait "WPEUTIL CreatePageFile /path=I:\pagefile.sys", vbHide
End If
ElseIf FolderExists("H:\") Then
ShellAndWait "WPEUTIL CreatePageFile /path=H:\pagefile.sys /size=256", vbHide
If Not FileExists("H:\pagefile.sys") Then
ShellAndWait "WPEUTIL CreatePageFile /path=H:\pagefile.sys", vbHide
End If
Else
MsgBox "This machine does not meet the minimum memory requirements and a USB device can not be located to create a pagefile.", vbOKOnly + vbCritical, "Critical Error"
End If
End If

End Sub

And for freeing up memory, I just stop a couple of services, gives back (if memory serves) about 4MB of RAM.

    
ShellAndWait "WPEUTIL DisableFirewall", vbHide
ShellAndWait "NET STOP MPSSVC", vbHide
ShellAndWait "NET STOP IKEEXT", vbHide
ShellAndWait "NET STOP EVENTLOG", vbHide

Edited by trtkron

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...