Solved

program that can't be deleted in windows

Posted on 2000-04-18
14
124 Views
Last Modified: 2010-04-04
write me code for program that can't be deleted in windows, that 'it is use for windows'?
0
Comment
Question by:Jurica2505
  • 4
  • 3
  • 2
  • +5
14 Comments
 
LVL 1

Expert Comment

by:tomer_engel
ID: 2728598
Sorry,What?
0
 

Expert Comment

by:dentener
ID: 2729749
The only way that I know of that a program really can't be deleted is when it's running...

Writing code is useless, because when the code is running, the program is running and thus the program can't be deleted...
0
 
LVL 5

Expert Comment

by:TheNeil
ID: 2729908
Do you mean a program that can't be closed?

What you could do is add the following line to the OnClose method of your form:

Action := caNone;

That'll stop the form from closing (ever)

The Neil
0
 
LVL 4

Expert Comment

by:jeurk
ID: 2730027
hello,
You can't do it directly.

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.

procedure DeleteLater(Filename: string);
var
  Wininit : string;
  Buffer : array[0..MAX_PATH] Of char;
  I,J : integer;
  Ini : TStringList;
begin
  FillChar(Buffer, SizeOf(Buffer), 0);
  GetWindowsDirectory(Buffer, SizeOf(Buffer));
  Wininit := IncludeTrailingBackslash(Buffer) + 'Wininit.ini';

  Ini := TStringList.Create;
  try
    if FileExists(Wininit) then Ini.LoadFromFile(Wininit);
    for I := 0 to Ini.Count - 1 do Ini[I] := Uppercase(Ini[I]);

    J := Ini.IndexOf('[RENAME]');
    if J = -1 then
      begin
      Ini.Add('[Rename]');
      J := 0;
      end;
    FillChar(Buffer, SizeOf(Buffer), 0);
    GetShortPathName(PChar(Filename), Buffer, SizeOf(Buffer));
    Ini.Insert(J+1, 'NUL=' + Buffer);
    Ini.SaveToFile(Wininit);
  finally
    Ini.Free;
  end;
end;

or
Question/Problem/Abstract:

How can I remove my Exe-file while my Application is still running?
Answer:


{ Here's the updated version; it seems that the unit doesn't
  work properly (thx to Guido Geurts). Anyway, it does delete
  the exe-file as described, but you've to close the App. In
  the meantime I will try to find a better version  - thx for
  your comprehension. btw, any comments are welcome }

uses
  Windows, SysUtils;

procedure DeleteMe;
var
  BatchFile: TextFile;
  BatchFileName: string;
  ProcessInfo: TProcessInformation;
  StartUpInfo: TStartupInfo;
begin
  { create a batchfile in the applications directory }
  BatchFileName := ExtractFilePath(ParamStr(0)) + '$$336699.bat';

  { open and write the file }
  AssignFile(BatchFile, BatchFileName);
  Rewrite(BatchFile);

  Writeln(BatchFile, ':try');
  Writeln(BatchFile, 'del "' + ParamStr(0) + '"');
  Writeln(BatchFile,
    'if exist "' + ParamStr(0) + '"' + ' goto try');
  Writeln(BatchFile, 'del "' + BatchFileName + '"');
  CloseFile(BatchFile);

  FillChar(StartUpInfo, SizeOf(StartUpInfo), $00);
  StartUpInfo.dwFlags := STARTF_USESHOWWINDOW;
  StartUpInfo.wShowWindow := SW_HIDE;

  if CreateProcess(nil, PChar(BatchFileName), nil, nil,
     False, IDLE_PRIORITY_CLASS, nil, nil, StartUpInfo,
     ProcessInfo) then
  begin
    CloseHandle(ProcessInfo.hThread);
    CloseHandle(ProcessInfo.hProcess);
  end;

end;

0
 
LVL 2

Expert Comment

by:craig_capel
ID: 2730155
dentener was correct, the only way to do it is by making it invisible so the user can not close it down, and put the code in startup.... but they still can go to dos and delete, theres no way around it...
0
 
LVL 4

Expert Comment

by:jeurk
ID: 2730261
oups, sorry, I understood you want to delete something that is running.
Sorry.
0
 

Expert Comment

by:dentener
ID: 2730420
Go to dos and set the system flag with attrib for your executable.

Something like attrib +s app.exe

Then normal users (who don't know attrib) can not delete the file under dos anymore....
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

Expert Comment

by:dentener
ID: 2730430
Add your executable to this registry key:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run

Most 'normal' users only know about the startup folder, but don't know about this key. The result is that the executable is executed every time windows is started. And a running executable can't be deleted....
0
 
LVL 3

Accepted Solution

by:
f15iaf earned 30 total points
ID: 2730832
go to

"start"\"shut down"\"reset in ms-dos mode",
when in ms-dos mode delete the files of the program.
0
 
LVL 2

Expert Comment

by:craig_capel
ID: 2730871
f15, please please read the question..... "write me code for program that can't be deleted in windows"
0
 

Expert Comment

by:dentener
ID: 2733534
You could try to ask your question in another way the next time, because 90% of us interpreted your question the wrong way...
0
 

Expert Comment

by:Begli
ID: 2736432
Yeah, funny way,

Hi, tenerife
0
 
LVL 2

Expert Comment

by:craig_capel
ID: 2736446
Begli?.. Tenerife? (how u know where i live? )
0
 
LVL 4

Expert Comment

by:Romi Kuntsman
ID: 2830884
Did you mean to make a program that locks it's file when you run it?
If you want, i can write the source for locking and unlocking a file.
The filename can be gained by "ParamStr(0)"
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now