2008. március 1., szombat

How can I tell the system to rename a file on the next reboot?


Problem/Question/Abstract:

How can I tell the system to rename a file on the next reboot?

Answer:

Windows has a mechanism to replace files that are currently in use on next boot. So what the program could do is

save the updated version under another name, preferably in the applications directory (source and target need to be on the same volume).

the execute the following code:

if Win32Platform = VER_PLATFORM_WIN32_NT then
  MoveFileEx(Pchar(tempFilenameWithPath),
    Pchar(realfilenamewithpath),
    MOVEFILE_REPLACE_EXISTING or MOVEFILE_DELAY_UNTIL_REBOOT)
else
  WritePrivateProfileString(
    'rename',
    Pchar(realfilenamewithpath),
    Pchar(tempFilenameWithPath),
    'wininit.ini');

Note that the wininit.ini file needs to be set up using the short (DOS 8.3) versions of long path and filenames.

Nincsenek megjegyzések:

Megjegyzés küldése