12

I'm trying to write a C#/.NET application that optimizes the hard drives for our XP workstations

  1. Set pagefile to "No paging file"
  2. Reboot
  3. Run a defrag utility to optimize the data and apps
  4. Create a contiguous page file
  5. Reboot, run pagedefrag from Sysinternals

I'm really struggling with #1. I delete the following key: SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management\PagingFiles

Upon reboot, the System Control Panel shows "No page file", but c:\pagefile.sys still exists and its in use by the SYSTEM process so I can't delete it and I can't optimize HD. I tried using PendingFileRenamingOperations and that bombs out too. I tried using WMI: Win32_PageFileSetting, but that only lets you set sizes (not zero--defaults to 2MB).

Of course, if I do the manual steps outlined above, it works.

I think I need an API call to make this happen.

MPelletier
  • 16,256
  • 15
  • 86
  • 137
NBPC77
  • 277
  • 4
  • 13
  • It appears the paging file is in use for one more boot cycle. On the second reboot the file is no longer in use. This is for Windows 7. – usr Apr 09 '16 at 21:16

3 Answers3

4

Look at Delete or DeleteEx methods of the Win32_PageFile class:

The class has been deprecated but since you're talking about Windows XP, maybe it wasn't deprecated then.

Hans Olsson
  • 54,199
  • 15
  • 94
  • 116
1

Actually, the mistake I made was delete the registry key.

What I had to do is set the multi-string value to something like

rk.SetValue("PagingFiles", new string[]{""}, RegistryValueType.MultiString)

Good luck!

NBPC77
  • 277
  • 4
  • 13
0

You can modify registry in order to change pagefile settings.

They are stored in the following registry's key:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management

PagingFiles value contains values in the 'PageFileLocation MinSize MaxSize' format (i.e. 'C:\pagefile.sys 1024 2048') -- you can find more on that in this article.

Regent
  • 5,502
  • 3
  • 33
  • 59
  • Actually, I'm trying to get rid of the pagefile (temporarily). I know there's a WMI call that does what you're saying, but XP says that's a no no (setting min and max to zero) and resets it to 2MB instead. – NBPC77 May 11 '10 at 23:12
  • @NBPC77: Possibly API restricts removing all page files. I do not have a pagefile on my system (8 GB of RAM is quite enough) and that `PagingFiles` value consist of two empty lines. – Regent May 12 '10 at 08:53