Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

On Windows XP, programmatically set Pagefile to "No Paging File" on single c: drive

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.

like image 527
NBPC77 Avatar asked May 11 '10 14:05

NBPC77


People also ask

How do I remove page file from C drive?

Right click on pagefile. sys and choose 'Delete'. If your pagefile is particularly large, the system may have to delete it immediately without sending it to the Recycle Bin. Once the file has been removed, restart your PC.

How do I turn off auto paging file size for all drives?

Choose the Advanced tab in the Performance Options dialog, and click the Change… button in the Virtual Memory section. In the Virtual Memory dialog, uncheck the “Automatically manage paging file size for all drives”. Then configure pagefiles so that any DataKeeper-protected volumes have no page file configured.

Should pagefile be on C drive?

Pagefile in Windows 10 is a hidden system file with the . SYS extension that is stored on your computer's system drive (usually C:\). The Pagefile allows the computer to perform smoothly by reducing the workload of the physical memory, or RAM.


2 Answers

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.

like image 194
Hans Olsson Avatar answered Nov 11 '22 15:11

Hans Olsson


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!

like image 20
NBPC77 Avatar answered Nov 11 '22 15:11

NBPC77