Author: Jérôme Tremblay
Sometimes I need to handle files that are used by windows before they are loaded in
the boot process, like a DLL or a VxD for example. How do I do that?
Windows NT have a function called MoveFileEx that deletes files at reboot if used
with the MOVEFILE_DELAY_UNTIL_REBOOT flag. Unfortunately, Windows 9x doesn't
support this flag. So what do we do?
Every time you reboot, windows look for a file called WININIT.INI in the Windows
directory. This file can contains Delete / Rename / Copy directives that will be
excuted before anything is loaded (or almost). You can place commands in the
[Rename] section using the syntax DESTINATION=SOURCE. If Destination is NUL, then
the file will be deleted. Filenames and paths must use SHORT FILENAMES (because
this file is processed before long filenames support is even loaded).
Please note that contrary to the example found in win32.hlp, you cannot use
WritePrivateProfileString() or TIniFile to access this file because there might be
duplicates values. If there is already one NUL value, TIniFile would overwrite it
instead of creating a new one. So you better use TStringList instead.
Here are some example entries:
Below is the function DeleteLater that will just add NUL=Filename to wininit.ini,
create the file if it doesn't exist, and also create the section if needed.
1 procedure DeleteLater(Filename: string);
3 Wininit: string;
4 Buffer: array[0..MAX_PATH] of char;
5 I, J: integer;
6 Ini: TStringList;
8 FillChar(Buffer, SizeOf(Buffer), 0);
9 GetWindowsDirectory(Buffer, SizeOf(Buffer));
10 Wininit := IncludeTrailingBackslash(Buffer) + 'Wininit.ini';
12 Ini := TStringList.Create;
14 if FileExists(Wininit) then
16 for I := 0 to Ini.Count - 1 do
17 Ini[I] := Uppercase(Ini[I]);
19 J := Ini.IndexOf('[RENAME]');
20 if J = -1 then
23 J := 0;
25 FillChar(Buffer, SizeOf(Buffer), 0);
26 GetShortPathName(PChar(Filename), Buffer, SizeOf(Buffer));
27 Ini.Insert(J + 1, 'NUL=' + Buffer);