Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

program that can't be deleted in windows

Posted on 2000-04-18
14
Medium Priority
?
148 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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
 

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 120 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Screencast - Getting to Know the Pipeline
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

876 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