Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm trying to set up an automated script for a Windows XP installer. It's a batch script that runs on first boot after installation, and among the things I'm trying to accomplish, is removing the pagefile from C: entirely, and putting a 16-768 MB pagefile on D: instead.

Here're my batch file instructions:

echo === Creating new page file on D: ...
cscript %windir%\system32\pagefileconfig.vbs /create /i 16 /m 768 /vo d: >nul
echo.
echo === Removing old page file from C: ...
cscript %windir%\system32\pagefileconfig.vbs /delete /vo C:
attrib -s -h c:\pagefile.sys
del c:\pagefile.sys

My problem is that while these are sane commands, the removal of the pagefile on C: requires me to reboot before those commands succeed.b Or, in other words — I have to first create the D: pagefile, then reboot and delete the c:\pagefile.sys file, or I'm stuck with a c:\pagefile.sys file which isn't even recognized by Windows itself (it'll just say that there's a page file on D:, and that C: has no pagefile at all). Obviously because already some pages are written to the C:\pagefile.sys file.

So how would I go about accomplishing this in one go? Or, in two gos, if this is "batch scriptable" :)

TIA, Daniel :)

EDIT: I should probably clarify: Running those commands above are all valid, but they'll only succeed fully if I re-run the "attrib" and "del" commands at next boot. The C: pagefile is in use at the time, so I cannot delete the file it uses, and Windows itself won't remove it when I configure it to not use C: as a page file drive. Instead, it'll leave an orphaned c:\pagefile.sys file behind (which is really large).

I don't necessarily need this to work in one go, registering the last two commands to run after a reboot would also be great :)

EDIT 2: As it seems not possible to do in one go, I basically just ended up doing the pagefile configuration as described above first, then dropped another batch file into "%userprofile%\Start Menu\Programs\Startup" that removes the orphaned file from C: on the first logon. It isn't the prettiest solution, but it works :)

share|improve this question
1  
Pretty sure you need to reboot. Look into the RunOnce registry key - use the local machine one (not current user). –  Bob Nov 11 '13 at 15:31
    
@Bob Thank you! I think I might be able to decipher something to do with my installation based on that. I'll report back :) –  DanielSmedegaardBuus Nov 11 '13 at 15:50
add comment

1 Answer

My problem is that while these are sane commands, the removal of the pagefile on C: requires me to reboot before those commands succeed.

Of course. You can expand the pagefile (increase its size or add one to a new volume) while Windows is running, but you cannot reduce it (reducing its size or removing it).

Or, in other words — I have to first create the D: pagefile, then reboot and delete the c:\pagefile.sys file

You can do them at the same time so that you only have to reboot once.

I'm stuck with a c:\pagefile.sys file which isn't even recognized by Windows itself (it'll just say that there's a page file on D:, and that C: has no pagefile at all). Obviously because already some pages are written to the C:\pagefile.sys file.

Running those commands above are all valid, but they'll only succeed fully if I re-run the "attrib" and "del" commands at next boot. The C: pagefile is in use at the time, so I cannot delete the file it uses, and Windows itself won't remove it when I configure it to not use C: as a page file drive. Instead, it'll leave an orphaned c:\pagefile.sys file behind (which is really large).

Correct. Windows has acknowledged your changes, but until you reboot, the pagefile is still in use and there is nothing it can do about it.

As it seems not possible to do in one go, I basically just ended up doing the pagefile configuration as described above first, then dropped another batch file into "%userprofile%\Start Menu\Programs\Startup" that removes the orphaned file from C: on the first logon. It isn't the prettiest solution, but it works :)

Or, you can use a program like MoveLater in your batch-file so that it gets done automatically by the system on reboot.

Note, this is different than running something from the Startup folder or even the Run registry keys; these programs write the files/folders to be moved/renamed/deleted to PendingFileRenameOperations which is processed very early in the boot process (technically before Windows even runs), so they can be used to delete even system files which simply cannot be deleted after Windows is up and running.

This is handy because sometimes Windows will detect certain files and folders as being “special” and even if it is configured not to use them, it will still lock them anyway, preventing you from deleting them while booted. By scheduling it to be deleted before Windows runs, you can nuke the files/folders so that Windows doesn’t even see them.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.