开发者

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

开发者 https://www.devze.com 2022-12-30 09:37 出处:网络
I\'m trying to write a C#/.NET application that optimizes the hard drives for our XP workstations Set pagefile to \"No paging file\"

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.


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.


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!


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号