Home > Windows Tips > > Relocate pagefile upon reboot
Win IT Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 


Relocate pagefile upon reboot


Serdar Yegulalp
03.19.2003
Rating: -3.08- (out of 5)


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


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.)

SHUTDOWN.VBS

on error resume next
drive1="C:"
drive2="D:"
pagefile="pagefile.sys 0 0"
dim strpagefile 
set WshShell=Wscript.Createobject("Wscript.shell")
location="HKLMSYSTEMCurrentControlSetControlSession
 ManagerMemory ManagementPagingFiles"
strpagefile=WshShell.RegRead(location)
if isnull(ubound(strpagefile)) then
 msgbox("No pagefile present! Creating one.")
 wshshell.run "reg add ""HKLMSYSTEMCurrentControlSetControlSession ManagerMemory 
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 ""HKLMSYSTEMCurrentControlSetControlSession ManagerMemory 
Management"" /v PagingFiles /t REG_MULTI_SZ /d """ & newfile & "pagefile.sys 0 0"""
end if
end if

STARTUP.VBS

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.


Rate this Tip
To rate tips, you must be a member of SearchWinIT.com.
Register now to start rating these tips. Log in if you are already a member.




Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   



RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary

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.



Windows Technology Updates, Reviews and Solutions

Laptop Discounts with free coupon codes, huge savings at Notebook Review

HomeNewsTopicsITKnowledge ExchangeTipsAsk the ExpertsMultimediaWhite PapersIT Downloads
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 1999 - 2009, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts