jwall Posted March 10, 2010 Share Posted March 10, 2010 I know how to set the size of the page file using vbs but I need to disable it altogether (ie set it to "No paging file" on an XP machine. I know it can be done with C:\WINDOWS\system32\pagefileconfig.vbs but I want to write it into a script I'm working on.To be more specific, I need one script that will disable it, then after rebooting I want to run another script that will set the min and max, the code I have for that is:Sub SetPF () Dim strComputer,oWMIService,colCSItems,oCSItem,colPageFiles,strRAMCount,oPageFile strComputer = "." Set oWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colCSItems = oWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystem") Set colPageFiles = oWMIService.ExecQuery ("Select * from Win32_PageFileSetting") ' Get the amount of installed physical memory For Each oCSItem In colCSItems strRAMCount = oCSItem.TotalPhysicalMemory / 1048576 Next ' Set the Min and Max page file size For Each oPageFile in colPageFiles oPageFile.InitialSize = Round(strRAMCount) oPageFile.MaximumSize = Round(strRAMCount * 1.5) oPageFile.Put_ NextEnd SubAnd this works, but I just ran a test using C:\WINDOWS\system32\pagefileconfig.vbs to delete the pf first and the script above does not enable it again so I need to add some code to it. Link to comment Share on other sites More sharing options...
gunsmokingman Posted March 11, 2010 Share Posted March 11, 2010 Perhaps Try This Script To See If It Does What You Want. Dim Act :Set Act = CreateObject("Wscript.Shell") Dim Wmi :Set Wmi = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2") Dim Col, Obj, Ram'-> Delete The Page Files For Each Obj In Wmi.ExecQuery("SELECT * FROM Win32_PageFile") Col = Obj.Delete Select case Col Case 0 : Col = "Success" Case 2 : Col = "Access Denied" Case 8 : Col = "Unspecified failure" Case 9 : Col = "Invalid object" Case 10 : Col = "Object already exists" Case 11 : Col = "File system not NTFS" Case 12 : Col = "Platform not NT/Windows 2000" Case 13 : Col = "Drive not the same" Case 14 : Col = "Directory not empty" Case 15 : Col = "Sharing violation" Case 16 : Col = "Invalid start file" Case 17 : Col = "Privilege not held" Case 21 : Col = "Invalid parameter" End Select Next'-> Results Act.Popup "Results : " & Col,7,"Delete Page File",4128'-> Get The Ram Size For Each Obj In Wmi.ExecQuery("SELECT * FROM Win32_ComputerSystem") Ram = FormatNumber(Obj.TotalPhysicalMemory / 1048576,2) Next'-> Reset The PageFile For Each Obj In Wmi.ExecQuery("SELECT * FROM Win32_PageFileSetting") Obj.InitialSize = Round(Ram) Obj.MaximumSize = Round(Ram * 1.5) Obj.Put_ Next'-> Reboot The Computer For Each Obj In Wmi.ExecQuery("SELECT * FROM Win32_OperatingSystem")'-> Values For This Class' 0 = "Log Off"' 4 = "Forced Log Off (0 + 4)"' 1 = "Shutdown"' 5 = "Forced Shutdown (1 + 4)"' 2 = "Reboot"' 6 = "Forced Reboot (2 + 4)"' 8 = "Power Off"' 12 ="Forced Power Off (8 + 4)" Obj.Shutdown(6) Next Link to comment Share on other sites More sharing options...
jwall Posted March 11, 2010 Author Share Posted March 11, 2010 Thanks for the code. I get the "Sharing violation" popup, which makes sense because pagefile.sys is in use, and then an error on line 46 of "Privilege not held".I'm sure the code to set no paging file is in C:\WINDOWS\system32\pagefileconfig.vbs andI've tried to find it but the script is so modularized I can't nail it down. Link to comment Share on other sites More sharing options...
gunsmokingman Posted March 11, 2010 Share Posted March 11, 2010 Line 46 of my code is thisObj.Shutdown(6)I have listed the values that go with the shutdown methodperhaps try for a forced rebootObj.Shutdown(2 + 4)Or just an normal rebootObj.Shutdown(2) Link to comment Share on other sites More sharing options...
jwall Posted March 11, 2010 Author Share Posted March 11, 2010 I'm not so worried about the restart but more concerned with deleting the page file. I know if we go to System Properties > Advanced tab > Performance settings > Advanced > Change, enable "No paging file" pagefile.sys gets deleted. I figure if there's a way to set the size of the page file there is a way to delete it. Link to comment Share on other sites More sharing options...
allen2 Posted March 19, 2010 Share Posted March 19, 2010 I'm not so worried about the restart but more concerned with deleting the page file. I know if we go to System Properties > Advanced tab > Performance settings > Advanced > Change, enable "No paging file" pagefile.sys gets deleted. I figure if there's a way to set the size of the page file there is a way to delete it.See in the registry there:HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Memory ManagementSet PagingFiles value to "" and Set ClearPageFileAtShutdown to "1"If the page file is in use (you booted Windows with it set before) it won't deleted until reboot doing it manualy as you explained or not. Hope this helps. Link to comment Share on other sites More sharing options...
deathcon1 Posted December 30, 2010 Share Posted December 30, 2010 I'm get the same error at line 46. Link to comment Share on other sites More sharing options...
cluberti Posted December 31, 2010 Share Posted December 31, 2010 See this to see if it helps any. 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