DL. Posted October 20, 2005 Share Posted October 20, 2005 I've created a batch (with included VB-script) to set the pagefile to a predefined size on the systemdrive and remove it from all other partitions.The problem is that it only works sometimes and not always. What's wrong with it?The reason for using a batch-file instead of just calling a VB-script is that if the pagefile happens to be placed on some other partition/drive, it will only resize it where it is. Using only the pagefileconfig.vbs present in system32 will not change/delete the pagefile if it hasn't previously been set manually.What the batch-file is supposed to do:1. Check if the .vbs-file is already present to determine what to do next:If the file is not present:2. Copy itself from the current directory to %systemroot%.3. Create a .vbs-file and run it.4. Check whether or not the pagefile is already in the systemdrive and if so change the size of it.5. If there is no pagefile in the systemdrive it will create it it and delete the other ones.6. It will add itself to Runonce and reboot. It will then continue:If the .vbs-file is already present (or has been created before the reboot):2b. Delete the pagefile from all other partitions since it is no longer in use.3b. Delete both the .vbs-file it created and itself.The batch-file is named Vxl.cmd (vxl is a shortening of växlingsfil=pagefile in Swedish, like pgf or something in English):cmdow @ /HID@ECHO OFF&setlocal enableextensions enabledelayedexpansionIF EXIST "%systemroot%\Vxl.vbs" GOTO :DE ELSE GOTO :DO:DOxcopy /s /q /h /k /y /r "%CD%\Vxl.cmd" "%systemroot%\"ECHO strComputer = ".">>%systemroot%\Vxl.vbsECHO Set objWMIService = GetObject("winmgmts:" _>>%systemroot%\Vxl.vbsECHO ^& "{impersonationLevel=impersonate}!\\" ^& strComputer ^& "\root\cimv2")>>%systemroot%\Vxl.vbsECHO Set colPageFiles = objWMIService.ExecQuery _>>%systemroot%\Vxl.vbsECHO ("Select * from Win32_PageFileSetting")>>%systemroot%\Vxl.vbsECHO For Each objPageFile in colPageFiles>>%systemroot%\Vxl.vbsECHO objPageFile.InitialSize = 10>>%systemroot%\Vxl.vbsECHO objPageFile.MaximumSize = 10>>%systemroot%\Vxl.vbsECHO objPageFile.Put_>>%systemroot%\Vxl.vbsECHO Next>>%systemroot%\Vxl.vbscscript //B "%systemroot%\vxl.vbs"IF EXIST "%systemdrive%\pagefile.sys" (cscript //B "%systemroot%\system32\pagefileconfig.vbs" /Change /I 1028 /M 1028 /VO %systemdrive% ) ELSE (cscript //B "%systemroot%\system32\pagefileconfig.vbs" /Create /I 1028 /M 1028 /VO %systemdrive% )FOR %%i IN (C D E F G H I J K L M N O P Q R S T U V W X Y Z) DO IF NOT %%i: == %systemdrive% (cscript //B "%systemroot%\system32\pagefileconfig.vbs" /Delete /VO %%i: )REG ADD HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce\ /V "Vxl" /D "%systemroot%\Vxl.cmd" /fGOTO EOF:DEFOR %%i IN (C D E F G H I J K L M N O P Q R S T U V W X Y Z) DO IF NOT %%i: == %systemdrive% (attrib -r -h -s -a "%%i:\pagefile.sys" & del /f /q "%%i:\pagefile.sys" )del /f /q "%systemroot%\Vxl.vbs"del /f /q "%systemroot%\Vxl.cmd"GOTO EOF2:EOFendlocalshutdown -r -t 0:EOF2endlocalEXIT(I could have used codebox tags on this, but I just couldn't figure out how to include blank lines.) Link to comment Share on other sites More sharing options...
Yzöwl Posted October 23, 2005 Share Posted October 23, 2005 (edited) There doesn't appear to be anything particularly wrong with the file you posted, a couple of possible pitfalls at most. The main one being, this can potentially include unrequired spaces%%i: == %systemdrive%Try this slight modification, I have left the structure the same, let us know of any improvement or change etc.@ECHO OFFCMDOW @ /HIDIF EXIST %SYSTEMROOT%\%~n0.vbs GOTO DECOPY %0 %SYSTEMROOT%>NULECHO strComputer = ".">>%SYSTEMROOT%\%~n0.vbsECHO Set objWMIService = GetObject("winmgmts:" _>>%SYSTEMROOT%\%~n0.vbsECHO ^& "{impersonationLevel=impersonate}!\\" ^& strComputer ^& "\root\cimv2")>>%SYSTEMROOT%\%~n0.vbsECHO.>>%SYSTEMROOT%\%~n0.vbsECHO Set colPageFiles = objWMIService.ExecQuery _>>%SYSTEMROOT%\%~n0.vbsECHO ("Select * from Win32_PageFileSetting")>>%SYSTEMROOT%\%~n0.vbsECHO.>>%SYSTEMROOT%\%~n0.vbsECHO For Each objPageFile in colPageFiles>>%SYSTEMROOT%\%~n0.vbsECHO objPageFile.InitialSize = 10 >>%SYSTEMROOT%\%~n0.vbsECHO objPageFile.MaximumSize = 10 >>%SYSTEMROOT%\%~n0.vbsECHO objPageFile.Put_>>%SYSTEMROOT%\%~n0.vbsECHO Next>>%SYSTEMROOT%\%~n0.vbsCSCRIPT //B //NOLOGO %SYSTEMROOT%\%~n0.vbsIF EXIST %SYSTEMDRIVE%\pagefile.sys ( CSCRIPT //B //NOLOGO "%SYSTEMROOT%\system32\pagefileconfig.vbs" /Change /I 1028 /M 1028 /VO %SYSTEMDRIVE%) ELSE ( CSCRIPT //B //NOLOGO "%SYSTEMROOT%\system32\pagefileconfig.vbs" /Create /I 1028 /M 1028 /VO %SYSTEMDRIVE%)FOR %%? IN (C D E F G H I J K L M N O P Q R S T U V W X Y Z) DO ( IF "%%?:" NEQ "%SYSTEMDRIVE%" ( IF EXIST %%?:\pagefile.sys CSCRIPT //B //NOLOGO %SYSTEMROOT%\system32\pagefileconfig.vbs /Delete /VO %%?: ))REG ADD HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce /V %~n0 /D "%SYSTEMROOT%\%~nx0" /FSHUTDOWN -r -f -t 10EXIT:DEFOR %%? IN (C D E F G H I J K L M N O P Q R S T U V W X Y Z) DO ( IF "%%?:" NEQ "%SYSTEMDRIVE%" ( IF EXIST %%?:\pagefile.sys DEL /A %%?:\pagefile.sys ))DEL %SYSTEMROOT%\%~n0.vbs %0<Edit>You can play with the shutdown delay but I would suggest leaving the force switch in and reducing the seconds one increment at a time.</Edit> Edited October 23, 2005 by Yzöwl Link to comment Share on other sites More sharing options...
DL. Posted October 23, 2005 Author Share Posted October 23, 2005 (edited) Yzöwl, I've been waiting for your post. You are probably the batchfile-expert of this forum.I'd like to learn more on the subject, do you know any good source for info?Did a few minor changes to the file and tried again:Replaced %CD% with . (why doesn't %CD% work?)Added -f and changed the shutdown timeout from 0 to 1If the size used in the vbs-script is too small, Windows will set the pagefile automatically. This is because it is smaller than the minimum usage. Setting a larger size (like around 70-120) will work, an even larger size can be set just to be on the safe side for different PC:s.The problem seems to be something with this part:IF EXIST "%systemdrive%\pagefile.sys" (cscript //B //NOLOGO "%systemroot%\system32\pagefileconfig.vbs" /Change /I 1028 /M 1028 /VO %systemdrive% ) ELSE (cscript //B //NOLOGO "%systemroot%\system32\pagefileconfig.vbs" /Create /I 1028 /M 1028 /VO %systemdrive% )Since it does everything else it's supposed to do, except from setting the size as specified. Pagefileconfig.vbs is present.It doesn't work if I run the first command (cscript...%systemdrive%) manually from the prompt (after setting it manually in the gui).It has worked before, but it won't work now. Edited October 23, 2005 by DL. Link to comment Share on other sites More sharing options...
Yzöwl Posted October 23, 2005 Share Posted October 23, 2005 The problem seems to be something with this part:IF EXIST "%systemdrive%\pagefile.sys" (cscript //B //NOLOGO "%systemroot%\system32\pagefileconfig.vbs" /Change /I 1028 /M 1028 /VO %systemdrive% ) ELSE (cscript //B //NOLOGO "%systemroot%\system32\pagefileconfig.vbs" /Create /I 1028 /M 1028 /VO %systemdrive% )Other than changing the order of the options, I cannot see anything wrong in those linesCSCRIPT %SYSTEMROOT%\%~n0.vbs //B //NOLOGOIF EXIST %SYSTEMDRIVE%\pagefile.sys ( CSCRIPT "%SYSTEMROOT%\system32\pagefileconfig.vbs" //B //NOLOGO /Change /I 1028 /M 1028 /VO %SYSTEMDRIVE%) ELSE ( CSCRIPT "%SYSTEMROOT%\system32\pagefileconfig.vbs" //B //NOLOGO /Create /I 1028 /M 1028 /VO %SYSTEMDRIVE%) Link to comment Share on other sites More sharing options...
DL. Posted October 24, 2005 Author Share Posted October 24, 2005 (edited) Have you tried it on your own system?The first part, using the created .vbs-file does work just fine. It is the part with pagefileconfig.vbs that doesn't work.I made the batchfile a few months ago and it was working very well back then. I recently made a few very small changes in it, but nothing that could affect the functionality. To make sure those settings didn't do anything I tried by using the original file, with the same results.After some more testing I'm not really sure that the problem is in the file.I've tried it on a few different configurations (all XP Pro and recently installed) with different results:In VMware:nLited (ver 1.0rc1, removed only a few components) with my own tweaks - not workingnLited (ver 1.0rc1, removed some more components) without any tweaks - not workingPhysical comps:With my own tweaks. - not workingStandard installation - workingDo you have any idea on what setting and/or component that might be causing this problem?I will take a look at my tweaks, but I'm not sure that I will find anything because I use a lot of tweaks (4000+ lines in a reg-file).What confuses me is that it is not working with the nLited, but totally untweaked installation.Update: Now I know that no service is causing this, tried on a clean install with only the services tweaked. Edited October 25, 2005 by DL. Link to comment Share on other sites More sharing options...
DL. Posted October 25, 2005 Author Share Posted October 25, 2005 I found it!Removing [HKEY_CLASSES_ROOT\CLSID\{7988B571-EC89-11cf-9C00-00AA00A14F56}] or "Disk and Profile Quota" in nLite will disable this functionality. Link to comment Share on other sites More sharing options...
Yzöwl Posted October 26, 2005 Share Posted October 26, 2005 I'm glad you found it, I don't use nLite, therefore couldn't for the life of me work out the problem. I even set up a couple of installations, just to test it, and it seemed okay. Link to comment Share on other sites More sharing options...
DL. Posted October 26, 2005 Author Share Posted October 26, 2005 I removed that reg-key with my tweakfile because I thought that it didn't do anything else except removing quota management. To remove only the quota tab in explorer you have to remove the next key, 7988B573-... (and not 7988B571-...).How did I figure it out?At first I tried only the tweaks to disable services (on a clean install), but that wasn't it.Then I targeted the section where I remove keys and searched the web for some info about each key (I don't keep that info in the file). Found the two most likely keys and tried them one at a time (after exporting them).@Yzöwl, as I asked you earlier in this thread do you know any good source for more info on advanced batch-scripting?Thanks for your help! Link to comment Share on other sites More sharing options...
S1LV3RF1$# Posted January 31, 2006 Share Posted January 31, 2006 (edited) Here Is a VB Script to accomplish this'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++' Name: ConfigurePageFile.vbs' Comments: This script examines curent phyiscal RAM and will ' create a page file twice the size'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++Option Explicit'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++' Variable Declaration'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++Dim strName, strInitialSize, strMaximumSize, objRtvPageFile, strMsgDim intRAM, int2XRAMDim objRAM, objSysSet, objItemDim valYNDim PageFileSz'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++' Main Body '++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++' Puts Total MB of Physical RAM into intRAM variableGetTotalRam()' Puts Page Config into variablesPageFileConfig()' Create MessageCreateMsg()' Twice Physical RAMint2XRAM = intRam * 2strMsg = strMsg & vbcrlf & "Would you like to set the Page File to "_ & vbcrlf & "2 X Total Physical Memory = " & int2XRAM & "?" & vbcrlf & vbcrlfvalYN = MsgBox (strMsg,vbYesNo,"Current Pagefile Settings and Total RAM")If valYN = 6 then ' Set current Page File to be two times RAM setPageFileSz(int2XRAM) strMsg = "Here are your new Page File settings:" & vbcrlf & vbcrlf CreateMsg() MsgBox strMsg,,"Current Pagefile Settings and Total RAM"Else WScript.echo "No Changes have been made."End If' Exit ScriptWScript.Quit(0)'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++' Sub Procedures and Functions'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++' Configure pagefileFunction setPageFileSz (PageFileSz) Dim objPageFile, objWMIService, colPageFiles Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\.\root\cimv2") Set colPageFiles = objWMIService.ExecQuery ("Select * from Win32_PageFileSetting") For Each objPageFile in colPageFiles objPageFile.InitialSize = PageFileSz objPageFile.MaximumSize = PageFileSz objPageFile.Put_ NextEnd Function' Retrieves Total Phyiscal RAM and Conerts to MBSub GetTotalRAM() For Each objRAM in GetObject("winmgmts:\\.\root\CIMV2").ExecQuery("SELECT TotalPhysicalMemory FROM Win32_ComputerSystem") intRAM = (objRAM.TotalPhysicalMemory / 1024) / 1024 intRAM = FormatNumber(intRAM, 0) + 1 NextEnd Sub' Retrieves Page File Name, Initial Size and Maximum Size into str variablesSub PageFileConfig() For Each objRtvPageFile in GetObject("winmgmts:\\.\root\CIMV2").ExecQuery("SELECT Name, InitialSize, MaximumSize FROM Win32_PageFileSetting",,48) strName = objRtvPageFile.Name strInitialSize = objRtvPageFile.InitialSize strMaximumSize = objRtvPageFile.MaximumSize NextEnd Sub' Put string together for messageSub CreateMsg() strMsg = strMsg & "Current Location:" & strName & vbcrlf strMsg = strMsg & "InitialSize: " & strInitialSize & vbcrlf strMsg = strMsg & "MaximumSize: " & strMaximumSize & vbcrlf strMsg = strMsg & "Total Physical Memory: " & intRAM & vbcrlfEnd Sub Edited January 31, 2006 by S1LV3RF1$# Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now