SetDeleteOnReboot function

Synopsis

BOOL SetDeleteOnReboot(
    LPCWSTR lpFileName
);

Parameters

lpFileNamePointer to a null‑terminated string that specifies the path of the file to be deleted. The file must be on the local computer.

Return value

If the function succeeds, the return value is TRUE. If the function fails, the return value is FALSE. To get extended error information, call GetLastError.

Requirements

  • Header: Winbase.h (include Windows.h)
  • Library: Kernel32.lib
  • Minimum supported client: Windows 2000

Remarks

The file is not deleted immediately. It is deleted after the system restarts, before any critical processes are started. This is useful for removing files that are in use.

Only files in the system drive can be marked for deletion. The calling process must have the appropriate privileges (SE_MANAGE_VOLUME_NAME).

Example

#include <windows.h>
#include <stdio.h>

int main(void)
{
    LPCWSTR file = L"C:\\Temp\\oldfile.txt";

    if (SetDeleteOnReboot(file))
        wprintf(L"File scheduled for deletion on next reboot.\n");
    else
        wprintf(L"Failed: %lu\n", GetLastError());

    return 0;
}

See also