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 drive1="C:\" drive2="D:\" pagefile="pagefile.sys 0 0" dim strpagefile set WshShell=Wscript.Createobject("Wscript.shell") location="HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management\PagingFiles" strpagefile=WshShell.RegRead(location) if isnull(ubound(strpagefile)) then msgbox("No pagefile present! Creating one.") wshshell.run "reg add ""HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management"" /v PagingFiles /t REG_MULTI_SZ /d ""c:\pagefile.sys 0 0""" else if ubound(strpagefile)>0 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) wshshell.run "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") f2.delete f3.delete
Serdar Yegulalp is the editor of the Windows 2000 Power Users Newsletter.