Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to delete or rename open files Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
23-Sep-03
Category
Files Operation
Language
Delphi 2.x
Views
236
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			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?

Answer:

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: 

[rename] 
NUL=C:\TEMP.TXT 
NUL=C:\TEMP2.TXT 
C:\NEW_DIR\EXISTING.TXT=C:\EXISTING.TXT 
C:\NEW_DIR\NEWNAME.TXT=C:\OLDNAME.TXT 
C:\EXISTING.TXT=C:\TEMP\NEWFILE.TXT 

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);
2   var
3     Wininit: string;
4     Buffer: array[0..MAX_PATH] of char;
5     I, J: integer;
6     Ini: TStringList;
7   begin
8     FillChar(Buffer, SizeOf(Buffer), 0);
9     GetWindowsDirectory(Buffer, SizeOf(Buffer));
10    Wininit := IncludeTrailingBackslash(Buffer) + 'Wininit.ini';
11  
12    Ini := TStringList.Create;
13    try
14      if FileExists(Wininit) then
15        Ini.LoadFromFile(Wininit);
16      for I := 0 to Ini.Count - 1 do
17        Ini[I] := Uppercase(Ini[I]);
18  
19      J := Ini.IndexOf('[RENAME]');
20      if J = -1 then
21      begin
22        Ini.Add('[Rename]');
23        J := 0;
24      end;
25      FillChar(Buffer, SizeOf(Buffer), 0);
26      GetShortPathName(PChar(Filename), Buffer, SizeOf(Buffer));
27      Ini.Insert(J + 1, 'NUL=' + Buffer);
28      Ini.SaveToFile(Wininit);
29    finally
30      Ini.Free;
31    end;
32  end;


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC