Monday, February 06, 2012
   
Text Size

XP - Set Pagefile size

'****************************************
'****** Set The PC's Page File Size to 2xRAM For Min and Max
'****************************************
Sub Set_PageFile_Size()
 On Error Resume Next
 sPath = "SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management\"

 Set WMI = GetObject("WinMgmts:")
 Set objs = WMI.InstancesOf("Win32_OperatingSystem")
 For Each obj In objs
   sMem = sMem & obj.TotalVisibleMemorySize
  If sMem < objs.Count Then sMem = sMem & ","
 Next

 sInstalled = CLng(sMem) / 1024
 sInstalled = cInt(sInstalled / 16) * 16
 sInstalled = sInstalled * 2

 set objRegistry = GetObject("WinMgmts://./root/default:StdRegProv")

 sPageFile = "C:\pagefile.sys "
 sPageFile = sPageFile & CStr(sInstalled) & " " & CStr(sInstalled)
 sPageFile = Array(sPageFile)

 lRC = objRegistry.SetMultiStringValue(HKEY_LOCAL_MACHINE, sPath, "PagingFiles", sPageFile )

 If (lRC 0) or (Err.Number 0) Then
  'An Error Occured Setting The Page File Size
  OFILES.Write (chr(13) & chr(10) & "PAGEFILE SIZE         : ERROR, There was a problem setting the Page File Size.")
 End If
 On Error GoTo 0
 OFILES.Write (chr(13) & chr(10) & "PAGEFILE SIZE         : Pagefile Size set to twice RAM Size for Minimum and Maximum.")
End Sub