Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Is anyone familiar with a script that can be set to run on startup that will report the status of physical memory installed in a machine?

I have a stock of Windows XP laptops and am dealing with the problem of RAM theft. When a user logs on, I would like them to be alerted if the physical memory is less than a pre-set amount (4GB). Even better would be is this change were noted in a log file only accessable by an administrator account.

share|improve this question
    
see if there's any way to lock the cases? :p –  Journeyman Geek Apr 6 '11 at 2:08

2 Answers 2

up vote 1 down vote accepted

There are vbscript commands that return the amount of system memory. Use this to write to a text or log file and either compare it to the previous amount and return an error if they do not match.

See here: http://community.spiceworks.com/scripts/show/409-find-network-machine-system-name-and-installed-memory

Since it returns an integer for system memory you could even set up a fudge factor to minimize false errors, say +/-30.

You could also use this to meet your secure reporting preference by appending the memory value and the date and time to a file in a secured folder and then using a script to poll the laptops regularly and report any where the values have changed and the date the change was recorded. That'll enable you to see when the variance was first recorded to enable better tracking of the problem.

UPDATE: Sysinternals (now owned by MS) has a utility, PSINFO, that reports various system information values remotely, similar to the script above. But it reports more than just memory. Have it run and report on start up, no script needed on the laptop. And then you'd only need the write an output collecting and parsing script and you'd be able to check multiple system values for variance.

share|improve this answer

It's more accurate to use the Capacity property of Win32_PhysicalMemory from WMI, rather than using the TotalPhysicalMemory property of Win32_ComputerSystem. That being said...

To alert users, you would probably want some kind of popup message. The VBScript below can be used as a user login script, either in your domain's GPO or using the local Group Policy editor (gpedit.msc). The script should be saved with a .vbs extension.

Option Explicit

Const TargetGBMemory = 4

Dim wmi
Dim physicalMemory
Dim mem
Dim resultsReturned
Dim totalMem

Set wmi = GetObject("winmgmts:\root\cimv2")
Set physicalMemory = wmi.ExecQuery ("SELECT Capacity FROM Win32_PhysicalMemory")

resultsReturned = False
On Error Resume Next
Err.Clear
mem = physicalMemory.Count
resultsReturned = CBool(Err.Number = 0)
Err.Clear
On Error Goto 0

totalMem = 0
If resultsReturned Then
    For Each mem In physicalMemory
        If Not IsNull(mem.Capacity) Then
            totalMem = CDbl(mem.Capacity)
        End If
    Next
End If

Set physicalMemory = Nothing
Set wmi = Nothing

If ((totalMem / (2 ^ 30)) < TargetGBMemory) Then
    WScript.Echo "Something happened to your memory. You only have", FormatNumber(totalMem / (2 ^ 30)), "GB."
End If

For the log file idea, you probably don't want any popups. Just write to the file and be quiet. You can use the script below in the same way, but you would want it as a machine startup script in the domain or local Group Policy. The script writes a file named "memory_log.txt" in the System folder. By default, this area is writable by admins only. Users would be able to see the log file and read it, but they couldn't delete or modify it. The script should be saved with a .wsf extension.

<package>

<job>

<object id="fso" progid="Scripting.FileSystemObject" />
<reference object="Scripting.FileSystemObject" />

<script language="VBScript">

Option Explicit

Const TargetGBMemory = 4

Dim wmi
Dim physicalMemory
Dim mem
Dim resultsReturned
Dim totalMem

Set wmi = GetObject("winmgmts:\root\cimv2")
Set physicalMemory = wmi.ExecQuery ("SELECT Capacity FROM Win32_PhysicalMemory")

resultsReturned = False
On Error Resume Next
Err.Clear
mem = physicalMemory.Count
resultsReturned = CBool(Err.Number = 0)
Err.Clear
On Error Goto 0

totalMem = 0
If resultsReturned Then
    For Each mem In physicalMemory
        If Not IsNull(mem.Capacity) Then
            totalMem = CDbl(mem.Capacity)
        End If
    Next
End If

Set physicalMemory = Nothing
Set wmi = Nothing


If ((totalMem / (2 ^ 30)) < TargetGBMemory) Then
    Dim ts
    Set ts = fso.OpenTextFile (fso.BuildPath (fso.GetSpecialFolder(SystemFolder), "memory_log.txt"), ForAppending, True)
    ts.Write Now
    ts.Write vbTab
    ts.WriteLine "Something happened to your memory. You only have " & FormatNumber(totalMem / (2 ^ 30)) & " GB."
    ts.Close
    Set ts = Nothing
End If

</script>

</job>

</package>
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.