Solved

program that can't be deleted in windows

Posted on 2000-04-18
14
143 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Suggested Courses
Course of the Month6 days, 12 hours left to enroll

623 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