Solved

program that can't be deleted in windows

Posted on 2000-04-18
14
134 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

809 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