IScript to change partition location of pagefile

G

Guest

I have a script that can change the size of the pagefile, but it only works
on the default, %systemroot%\pagefile.sys.

We have our pagefile on another partition, and i need it to change that
pagefile size on that partition. Here is the script.


'++Description:
'Dynamically modifies default pagefile size based on the amount of RAM in
the local computer.
'
'--Description

'++More Info :
'
'
'--More Info

'++Keywords :
'++Source :

''!!Note: This header block is used to populate the fields in the database
'when the file is imported.
'--Header


'Sets min and max pagefile size
'to some (specified) factor of RAM.
'Mainly developed to dynamically set pagefile
'during automated XP build process.
'Seems also to work on Win2k. As is, modifies
'only pagefiles that are in Windows' default
'location (e.g., c:\pagefile.sys if windows
'is in C:\Windows).

'Dave Motovidlak
'03/27/02

Option Explicit

Dim objShl
Dim objMem
Dim objModule
Dim objPageFile

Dim intMem
Dim intRamfactor
Dim strSysdrv
Dim strDefaultpagefile

Set objShl=CreateObject("WScript.Shell")
strSysdrv=objShl.ExpandEnvironmentStrings("%systemdrive%")

'The default page file is put on the systemdrive with this name...
strDefaultpagefile=strSysdrv & "\pagefile.sys"

'This number times your RAM is the size your pagefile will be.
intRamfactor=3

'Connect to the Win32_OperatingSystem class on the local PC 'and count up
the memory.
Set objMem=GetObject("WinMgmts:root/cimv2:Win32_OperatingSystem")
For each objModule in objMem.Instances_
intMem=intMem + objModule.TotalVisibleMemorySize
Next

'Convert to MB.
intMem=Int(intMem/1024)

'Unfortunately the Win32_OperatingSystem class doesn't report
'actual physical memory but just what Windows sees as available
'to itself (and the Win32_PhysicalMemory class doesn't seem to work
'on all computers). This code will round up the number to the next nearest
'even number to account for the minute difference.
If intMem Mod 2 <>0 Then intMem=intMem+1

'Get a handle on the default pagefile.
Set objPageFile=GetObject("WinMgmts:root/cimv2:Win32_PageFileSetting=" &
chr(39) & strDefaultpagefile & chr(39))

'Make the min and max size of the pagefile the same
'to avoid fragmentation and therefore boost performance.

objPageFile.InitialSize=intMem*intRamfactor
objPageFile.MaximumSize=intMem*intRamfactor
objPageFile.Put_

Set objPageFile=Nothing
Set objMem=Nothing
Set objShl=Nothing
 
C

Carey Frisch [MVP]

Moving the pagefile to a different partition on the same hard drive
will not result in a performance gain since the system will require
additional seek time. The only way to actually gain a bit of performance
is to move the pagefile to a partition located on a different hard drive.

Virtual Memory in Windows XP
http://aumha.org/win5/a/xpvm.htm

[Courtesy of Alex Nichol, MS-MVP]

--
Carey Frisch
Microsoft MVP
Windows XP - Shell/User
Microsoft Newsgroups

Get Windows XP Service Pack 2 with Advanced Security Technologies:
http://www.microsoft.com/athome/security/protect/windowsxp/choose.mspx

-------------------------------------------------------------------------------------------

:

| I have a script that can change the size of the pagefile, but it only works
| on the default, %systemroot%\pagefile.sys.
|
| We have our pagefile on another partition, and i need it to change that
| pagefile size on that partition. Here is the script.
|
|
| '++Description:
| 'Dynamically modifies default pagefile size based on the amount of RAM in
| the local computer.
| '
| '--Description
|
| '++More Info :
| '
| '
| '--More Info
|
| '++Keywords :
| '++Source :
|
| ''!!Note: This header block is used to populate the fields in the database
| 'when the file is imported.
| '--Header
|
|
| 'Sets min and max pagefile size
| 'to some (specified) factor of RAM.
| 'Mainly developed to dynamically set pagefile
| 'during automated XP build process.
| 'Seems also to work on Win2k. As is, modifies
| 'only pagefiles that are in Windows' default
| 'location (e.g., c:\pagefile.sys if windows
| 'is in C:\Windows).
|
| 'Dave Motovidlak
| '03/27/02
|
| Option Explicit
|
| Dim objShl
| Dim objMem
| Dim objModule
| Dim objPageFile
|
| Dim intMem
| Dim intRamfactor
| Dim strSysdrv
| Dim strDefaultpagefile
|
| Set objShl=CreateObject("WScript.Shell")
| strSysdrv=objShl.ExpandEnvironmentStrings("%systemdrive%")
|
| 'The default page file is put on the systemdrive with this name...
| strDefaultpagefile=strSysdrv & "\pagefile.sys"
|
| 'This number times your RAM is the size your pagefile will be.
| intRamfactor=3
|
| 'Connect to the Win32_OperatingSystem class on the local PC 'and count up
| the memory.
| Set objMem=GetObject("WinMgmts:root/cimv2:Win32_OperatingSystem")
| For each objModule in objMem.Instances_
| intMem=intMem + objModule.TotalVisibleMemorySize
| Next
|
| 'Convert to MB.
| intMem=Int(intMem/1024)
|
| 'Unfortunately the Win32_OperatingSystem class doesn't report
| 'actual physical memory but just what Windows sees as available
| 'to itself (and the Win32_PhysicalMemory class doesn't seem to work
| 'on all computers). This code will round up the number to the next nearest
| 'even number to account for the minute difference.
| If intMem Mod 2 <>0 Then intMem=intMem+1
|
| 'Get a handle on the default pagefile.
| Set objPageFile=GetObject("WinMgmts:root/cimv2:Win32_PageFileSetting=" &
| chr(39) & strDefaultpagefile & chr(39))
|
| 'Make the min and max size of the pagefile the same
| 'to avoid fragmentation and therefore boost performance.
|
| objPageFile.InitialSize=intMem*intRamfactor
| objPageFile.MaximumSize=intMem*intRamfactor
| objPageFile.Put_
|
| Set objPageFile=Nothing
| Set objMem=Nothing
| Set objShl=Nothing
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top