Welcome to MSFN

Register now to gain access to all of our features. Once registered and logged in, you will be able to contribute to this site by submitting your own content or replying to existing content. You'll be able to customize your profile, receive reputation points as a reward for submitting content, while also communicating with other members via your own private inbox, plus much more! This message will be removed once you have signed in.


jwall

Set pagefile in XP with vbs

8 posts in this topic

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.

0

Share this post


Link to post
Share on other sites

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

0

Share this post


Link to post
Share on other sites

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.

0

Share this post


Link to post
Share on other sites

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)

0

Share this post


Link to post
Share on other sites

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.

0

Share this post


Link to post
Share on other sites

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.

0

Share this post


Link to post
Share on other sites

See this to see if it helps any.

0

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.