Jump to content

Welcome to MSFN Forum
Register now to gain access to all of our features. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more. This message will be removed once you have signed in.
Login to Account Create an Account



Photo

Set pagefile in XP with vbs

- - - - -

  • Please log in to reply
7 replies to this topic

#1
jwall

jwall
  • Member
  • 3 posts
  • Joined 10-March 10
  • OS:none specified
  • Country: Country Flag
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.


How to remove advertisement from MSFN

#2
gunsmokingman

gunsmokingman

    MSFN Master

  • Super Moderator
  • 2,430 posts
  • Joined 02-August 03
  • OS:none specified
  • Country: Country Flag
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




GunSmokingMan



#3
jwall

jwall
  • Member
  • 3 posts
  • Joined 10-March 10
  • OS:none specified
  • Country: Country Flag
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
gunsmokingman

gunsmokingman

    MSFN Master

  • Super Moderator
  • 2,430 posts
  • Joined 02-August 03
  • OS:none specified
  • Country: Country Flag
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)



GunSmokingMan



#5
jwall

jwall
  • Member
  • 3 posts
  • Joined 10-March 10
  • OS:none specified
  • Country: Country Flag
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
allen2

allen2

    Not really Newbie

  • Member
  • PipPipPipPipPipPipPip
  • 1,814 posts
  • Joined 13-January 06

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
deathcon1

deathcon1
  • Member
  • 5 posts
  • Joined 17-September 07
I'm get the same error at line 46.

#8
cluberti

cluberti

    Gustatus similis pullus

  • Supervisor
  • 11,253 posts
  • Joined 09-September 01
  • OS:Windows 8.1 x64
  • Country: Country Flag
See this to see if it helps any.
MCTS Windows Internals, MCITP Server 2008 EA, MCTS MDT/BDD, MCSE/MCSA Server 2003, Server 2012, Windows 8
--------------------
Please read the rules before posting!
Please consider donating to MSFN to keep it up and running!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users