How to use the Wininit.ini to delete files on startup (Views: 101)


Can anyone tell me how to delete several files using wininit.ini please?I've seen an example somewhere that included the following :


Using the regular inifile calls, I cant use the above method for deleting several files because each WriteString would overwrite previous "NULL=" entries. I'm unable to find any info about using wininit.ini anywhere, there might be a [delete] section for all I know.


This will do the job:

procedure DeleteAtReboot(FileList: TStringList);
  SList: TStringList;
  szContents: string;
  i, SectionFoundIndex: Integer;
  WinDir: array[0..MAX_PATH] of char;
  WinFile: string;
  if Win32Platform = VER_PLATFORM_WIN32_NT then
    {Use MoveFileEx}
    for i := 0 to FileList.count - 1 do
      MoveFileEx(PChar(FileList[i]), nil, MOVEFILE_DELAY_UNTIL_REBOOT);
    GetWindowsDirectory(WinDir, MAX_PATH);
    WinFile := IncludeTrailingBackslash(WinDir) + 'Wininit.ini';
    SList := TStringList.Create;
      SectionFoundIndex := -1;
      {Load it if it exists}
      if FileExists(WinFile) then
      for i := 0 to SList.Count - 1 do
        szContents := uppercase(SList[i]);
        if UpperCase(SList[i]) = '[RENAME]' then
          SectionFoundIndex := i;
      {Rename Section doesn't exist...}
      if SectionFoundIndex = -1 then
        SectionFoundIndex := SList.Add('[Rename]');
      {Now Add our Files}
      for i := 0 to FileList.count - 1 do
        SList.Insert(SectionFoundIndex + 1, 'NUL=' + FileList[i]);

<< Back to main page