Managing Page Files

Microsoft® Windows® 2000 Scripting Guide

The Windows 2000 operating system supports virtual memory. With virtual memory, a special file on a hard disk (known as a page file or a swap file) is used to supplement the physical memory installed on a computer. When a computer begins to run low on physical memory, data can be "swapped out" to the page file. This has the following advantages:

  • It frees up physical memory.

  • It makes it relatively fast and easy to retrieve the data, because the system knows exactly where to look for it.

Page files and virtual memory are extremely important to fast and effective computing. Without page files, computers would need double or triple the amount of physical memory in order to achieve the same level of performance.

System administrators need to review page file settings as part of a management routine that ensures that page files have been sized optimally and that each drive on a computer has its own page file. In addition, page file usage should be monitored on a regular basis; excessive paging often means that a computer has too little physical memory to carry out the tasks assigned to it.

WMI has several classes that can be used to help manage page files, including the Win32_PageFile class, which returns detailed information about each page file on a computer. Table 10.10 shows several of the key properties of this class.

Table 10.10 Win32_PageFile Properties

Property

Description

CreationDate

File creation date.

CSName

Name of the computer system.

Description

Description of the object.

Drive

Drive letter (including colon) of the file.

EightDotThreeFileName

MS-DOS-compatible file name for this file.

FileSize

Size of the file (in bytes).

InitialSize

Initial size of the page file, in megabytes.

InstallDate

Date the page file was created.

MaximumSize

Maximum size of the page file as set by the user. The operating system does not allow the page file to exceed this limit.

Name

File name of the page file.

Path

Path of the file. This includes leading and trailing backslashes.

Scripting Steps

Listing 10.19 contains a script that enumerates the properties of all the page files 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_PageFile class.

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

  4. For each page file in the collection, echo the values of such properties as the file name, current file size, initial file size, and maximum file size.

Listing 10.19 Enumerating Page File Properties

  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
 & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colPageFiles = objWMIService.ExecQuery _
 ("SELECT * FROM Win32_PageFile")
For each objPageFile in colPageFiles
 Wscript.Echo "Creation Date: " & objPageFile.CreationDate
 Wscript.Echo "Description: " & objPageFile.Description
 Wscript.Echo "Drive: " & objPageFile.Drive 
 Wscript.Echo "FileName: " & objPageFile.FileName 
 Wscript.Echo "FileSize: " & objPageFile.FileSize 
 Wscript.Echo "InitialSize: " & objPageFile.InitialSize
 Wscript.Echo "InstallDate: " & objPageFile.InstallDate
 Wscript.Echo "MaximumSize: " & objPageFile.MaximumSize
 Wscript.Echo "Name: " & objPageFile.Name 
 Wscript.Echo "Path: " & objPageFile.Path 
Next