Systems that get heavy usage may experience pagefile fragmentation, which can have an adverse impact on performance. One way to get around this, especially if the system has multiple hard drives (or hard drive partitions), is to have Windows automatically relocate the pagefile on each reboot and delete the old file.

One way to do this is through the use of a pair of scripts – one that runs at shutdown (which can be set through the Group Policy snap-in) and another that runs at startup (which can simply be placed in a user's Startup folder). The script to run at shutdown, SHUTDOWN.VBS, edits the Registry to set the pagefile to another partition, so that on the next reboot a new file is created. The startup script, STARTUP.VBS, deletes any old pagefiles.

To make things simple, STARTUP.VBS will try to delete both files—but won't be able to delete the file in use by the system, and will then simply either skip ahead to the other file or terminate normally. (The ON ERROR RESUME NEXT statement at the top will prevent it from balking.)


on error resume next
pagefile="pagefile.sys 0 0"
dim strpagefile 
set WshShell=Wscript.Createobject("")
 Manager\Memory Management\PagingFiles"
if isnull(ubound(strpagefile)) then
 msgbox("No pagefile present! Creating one.") "reg add ""HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Memory 
Management"" /v PagingFiles /t REG_MULTI_SZ /d ""c:\pagefile.sys 0 0"""

if ubound(strpagefile)>0

Requires Free Membership to View

then wshshell.regdelete(location) wshshell.regwrite(location),drive1 & pagefile, "REG_MULTI_SZ" else if left(strpagefile(0),3)=drive1 then newfile=drive2 else newfile=drive1 end if wshshell.regdelete(location) "reg add ""HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management"" /v PagingFiles /t REG_MULTI_SZ /d """ & newfile & "pagefile.sys 0 0""" end if end if


on error resume next
Set fso = CreateObject("Scripting.FileSystemObject")
Set f2 = fso.GetFile("c:\pagefile.sys")
Set f3 = fso.GetFile("d:\pagefile.sys")

Serdar Yegulalp is the editor of the Windows 2000 Power Users Newsletter.

This was first published in March 2003

There are Comments. Add yours.

TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.