MSFN Forum: Set pagefile in XP with vbs - MSFN Forum

Jump to content


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Set pagefile in XP with vbs Rate Topic: -----

#1 User is offline   jwall 

  • Group: Members
  • Posts: 3
  • Joined: 10-March 10
  • OS:none specified
  • Country: Country Flag

Posted 10 March 2010 - 03:21 PM

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_
 Next
End Sub


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


#2 User is offline   gunsmokingman 

  • MSFN Master
  • Group: Super Moderator
  • Posts: 2,350
  • Joined: 02-August 03
  • OS:none specified
  • Country: Country Flag

Posted 10 March 2010 - 07:28 PM

Perhaps Try This Script To See If It Does What You Want.

Quote

 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




#3 User is offline   jwall 

  • Group: Members
  • Posts: 3
  • Joined: 10-March 10
  • OS:none specified
  • Country: Country Flag

Posted 11 March 2010 - 09:19 AM

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.

#4 User is offline   gunsmokingman 

  • MSFN Master
  • Group: Super Moderator
  • Posts: 2,350
  • Joined: 02-August 03
  • OS:none specified
  • Country: Country Flag

Posted 11 March 2010 - 10:50 AM

Line 46 of my code is this
Obj.Shutdown(6)

I have listed the values that go with the shutdown method
perhaps try for a forced reboot
Obj.Shutdown(2 + 4)

Or just an normal reboot
Obj.Shutdown(2)


#5 User is offline   jwall 

  • Group: Members
  • Posts: 3
  • Joined: 10-March 10
  • OS:none specified
  • Country: Country Flag

Posted 11 March 2010 - 11:50 AM

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.

#6 User is offline   allen2 

  • Not really Newbie
  • PipPipPipPipPipPipPip
  • Group: Members
  • Posts: 1,731
  • Joined: 13-January 06

Posted 19 March 2010 - 05:00 PM

View Postjwall, on 11 March 2010 - 11:50 AM, said:

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 Management
Set 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.

#7 User is offline   deathcon1 

  • Group: Members
  • Posts: 5
  • Joined: 17-September 07

Posted 30 December 2010 - 03:41 PM

I'm get the same error at line 46.

#8 User is offline   cluberti 

  • Gustatus similis pullus
  • Group: Supervisor
  • Posts: 11,208
  • Joined: 09-September 01
  • OS:Windows RT
  • Country: Country Flag

Posted 31 December 2010 - 11:34 AM

See this to see if it helps any.

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

2 User(s) are reading this topic
0 members, 2 guests, 0 anonymous users



All trademarks mentioned on this page are the property of their respective owners
Copyright © 2001 - 2013 msfn.org
Privacy Policy