Deleting

How to make with Delphi that you could not delete a program(made in delphi)-when someone tries to delete program message"Can not delete!" must shows.
darko_poljakAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
LuKConnect With a Mentor Commented:
Write your programm in the Autostart-registrykey with a paramter.
Then make sure, that the first entry of the uses-list of your projectfile is a unit, that you can edit. write this into the interfacepart of your unit:
Function RegisterServiceProcess(id,state:integer):bool;stdcall;external 'shell32.dll';

write this directly before the 'end.' in your unit:

initialization
if paramstr(1)='your paramter' then begin
registerserviceprocess(getcurrentprocessid,1);
sleep(infinite);
end.

That will make your programm memory-resistent, so the user can't delete it.
0
 
simonetCommented:
>"Can not delete!"

That message is given when trying to delete a file that has been locked by Windows. Files are locked when they are open (being used).

Unless your file is something like a service, that stays open all the time, you can write a seconf program that constantly watches your file for changes. The backbone of this monitor file would be an API call called FindFirstChangeNotification.

Another option, simplier, is to mark your file as read-only.

Alex
0
All Courses

From novice to tech pro — start learning today.