Configuring Page File Properties

Microsoft® Windows® 2000 Scripting Guide

When you install Windows on a computer, the operating system automatically sets up and configures a page file for you. In many cases, those settings will be adequate, and you will never need to reconfigure the page file.

In other cases, however, the settings might prove less than optimal. If a page file is too small, applications might run short on virtual memory. If a page file is too large, you might be wasting disk space that could be used for other purposes. In either case, you can reconfigure the page file settings in order to promote faster and more efficient computing.

You can use the Win32_PageFileSetting class to modify both the initial size and the maximum size of any page file on your computer. Table 10.12 describes the properties of the Win32_PageFileSetting class.

note Note

  • You must restart the computer before the new page file settings take effect.

Table 10.12 Win32_PageFileSetting Properties

Property

Description

InitialSize

Initial size of the page file, in megabytes.

MaximumSize

Maximum size of the page file, in megabytes.

Name

Path and file name of the page file.

Scripting Steps

Listing 10.21 contains a script that configures the page file properties on a computer. To carry out this task, the script must perform the following steps:

  1. Create a variable to specify the computer name.

  2. Use a GetObject call to connect to the WMI namespace root\cimv2, and set the impersonation level to "impersonate."

  3. Use the ExecQuery method to query the Win32_PageFileSetting class.

    This returns a collection of all the page files on the computer.

  4. For each page file in the collection, set the InitialSize to 300 MB and the MaximumSize to 600 MB.

  5. Use the Put_ method to apply the changes and modify the page file settings.

Listing 10.21 Configuring Page File Properties

  
1
2
3
4
5
6
7
8
9
10
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
 & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colPageFiles = objWMIService.ExecQuery _
 ("SELECT * FROM Win32_PageFileSetting")
For Each objPageFile in colPageFiles
 objPageFile.InitialSize = 300
 objPageFile.MaximumSize = 600
 objPageFile.Put_
Next