title: On Windows XP, programmatically set Pagefile to "No Paging File" on single c: drive
body: <p>I'm trying to write a C#/.NET application that optimizes the hard drives for our XP workstations</p>
  
  <ol>
  <li>Set pagefile to "No paging file"</li>
  <li>Reboot</li>
  <li>Run a defrag utility to optimize the data and apps</li>
  <li>Create a contiguous page file</li>
  <li>Reboot, run pagedefrag from Sysinternals</li>
  </ol>
  
  <p>I'm really struggling with #1.  I delete the following key:
  SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management\PagingFiles</p>
  
  <p>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). </p>
  
  <p>Of course, if I do the manual steps outlined above, it works.  </p>
  
  <p>I think I need an API call to make this happen.</p>