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 use the Wininit.ini to delete files on startup 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
10-Oct-02
Category
System
Language
Delphi 2.x
Views
89
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Jonas Bilinkevicius 

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

[Rename]
NULL=C:\temp\readme.txt

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.

Answer:

This will do the job:
1   
2   procedure DeleteAtReboot(FileList: TStringList);
3   var
4     SList: TStringList;
5     szContents: string;
6     i, SectionFoundIndex: Integer;
7     WinDir: array[0..MAX_PATH] of char;
8     WinFile: string;
9   begin
10    if Win32Platform = VER_PLATFORM_WIN32_NT then
11    begin
12      {Use MoveFileEx}
13      for i := 0 to FileList.count - 1 do
14        MoveFileEx(PChar(FileList[i]), nil, MOVEFILE_DELAY_UNTIL_REBOOT);
15    end
16    else
17    begin
18      GetWindowsDirectory(WinDir, MAX_PATH);
19      WinFile := IncludeTrailingBackslash(WinDir) + 'Wininit.ini';
20      SList := TStringList.Create;
21      try
22        SectionFoundIndex := -1;
23        {Load it if it exists}
24        if FileExists(WinFile) then
25          SList.LoadFromFile(WinFile);
26        for i := 0 to SList.Count - 1 do
27        begin
28          szContents := uppercase(SList[i]);
29          if UpperCase(SList[i]) = '[RENAME]' then
30          begin
31            SectionFoundIndex := i;
32            break;
33          end;
34        end;
35        {Rename Section doesn't exist...}
36        if SectionFoundIndex = -1 then
37          SectionFoundIndex := SList.Add('[Rename]');
38        {Now Add our Files}
39        for i := 0 to FileList.count - 1 do
40          SList.Insert(SectionFoundIndex + 1, 'NUL=' + FileList[i]);
41        SList.SaveToFile(WinFile);
42      finally
43        SList.Free;
44      end;
45    end;
46  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