Solved

program that can't be deleted in windows

Posted on 2000-04-18
14
128 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

867 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

15 Experts available now in Live!

Get 1:1 Help Now