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