Recent

Author Topic: Uncloseable App.  (Read 6228 times)

Jake012345

  • Sr. Member
  • ****
  • Posts: 270
  • Knowledge is the key
Uncloseable App.
« on: June 12, 2020, 12:34:39 am »
Hello!

How can I deny to user to destroy the form?
I did it:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormClose(Sender: TObject; var CloseAction: TCloseAction);
  2. begin
  3.   if PasswordBox('Authentication','Type the password:')<>'asd' then
  4.   CloseAction:=caNone;
  5. end;
  6.  

But they can Destroy it with taskmanager. And it calls the OnDestroy but there is no closeaction..

jamie

  • Hero Member
  • *****
  • Posts: 7902
Re: Uncloseable App.
« Reply #1 on: June 12, 2020, 12:38:55 am »
let them destroy it...

You set a flag somewhere.. .and if this flag isn't set when the destroy happens then invalidate anything that happen...
The only true wisdom is knowing you know nothing

Jake012345

  • Sr. Member
  • ****
  • Posts: 270
  • Knowledge is the key
Re: Uncloseable App.
« Reply #2 on: June 12, 2020, 12:45:27 am »
Can I execute a restarter .bat (or anything) from OnDestroy?

jamie

  • Hero Member
  • *****
  • Posts: 7902
Re: Uncloseable App.
« Reply #3 on: June 12, 2020, 12:52:32 am »
That type of program is not welcomed in most places...

Although I know how to do it I won't... Sorry..
The only true wisdom is knowing you know nothing

Raul_ES

  • Full Member
  • ***
  • Posts: 183
  • My interests: Healthcare & Computers
    • My Linkedin Profile, you can add me to stay in contact.
Re: Uncloseable App.
« Reply #4 on: June 12, 2020, 12:56:05 am »
I use the onFormCloseQuery event the following way (adapt to your needs)t:

Code: Pascal  [Select][+][-]
  1. procedure TmainForm.FormCloseQuery(Sender: TObject; var CanClose: boolean);
  2. begin
  3.   if ServerOn = True then // or if authenthicate()='user whoever is banned for closing' not in "vip user list"
  4.   begin
  5.   CanClose := False;
  6.   ShowMessage('Close server first!')
  7.   end else if ServerOn = False then
  8.   begin
  9.   CanClose := False;
  10.   uEButton_quitClick(nil) // procedure to terminate the application, close files, databases, sockets...
  11.   end;
  12. end;
« Last Edit: June 12, 2020, 12:59:09 am by Raul_ES »
Pharmacy + Chemistry + Biology + Healthcare + Computing

If you have any interest or project related with these areas feel free to contact me!

jamie

  • Hero Member
  • *****
  • Posts: 7902
Re: Uncloseable App.
« Reply #5 on: June 12, 2020, 12:57:43 am »
Yeah but he's trying to force the app to stay alive no matter what.. That type of program is not welcomed where I come from.
The only true wisdom is knowing you know nothing

Jake012345

  • Sr. Member
  • ****
  • Posts: 270
  • Knowledge is the key
Re: Uncloseable App.
« Reply #6 on: June 12, 2020, 01:08:10 am »
I write it to Deny the access to selected files with open those with TFileStream.create(...,fmDeny).
I trying to do my idea in an older topic.


Quote
Yeah but he's trying to force the app to stay alive no matter what.. That type of program is not welcomed where I come from.
If you know an easier way I'll happy.

Jake012345

  • Sr. Member
  • ****
  • Posts: 270
  • Knowledge is the key
Re: Uncloseable App.
« Reply #7 on: June 12, 2020, 01:18:32 am »
And sure I want to run it without window, (at most with TrayIcon) so the taskmanager is the biggest problem.

form the topic:
Quote
if someone using the same computer corrupted the files either by accident or on purpose.
So not enough a warning that says 'Hey! that's not yours so keep away yourself!'.

ASBzone

  • Hero Member
  • *****
  • Posts: 733
  • Automation leads to relaxation...
    • Free Console Utilities for Windows (and a few for Linux) from BrainWaveCC
Re: Uncloseable App.
« Reply #8 on: June 12, 2020, 01:30:23 am »
Hello!

How can I deny to user to destroy the form?
I did it:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormClose(Sender: TObject; var CloseAction: TCloseAction);
  2. begin
  3.   if PasswordBox('Authentication','Type the password:')<>'asd' then
  4.   CloseAction:=caNone;
  5. end;
  6.  

But they can Destroy it with taskmanager. And it calls the OnDestroy but there is no closeaction..

Can you give us some more information about what this application is supposed to be accomplishing?

It is very hard to create processes that cannot be killed by Task Manager (or the appropriate API), and typically, Windows reserves that ability to key kernel level processes.

Understanding why you are trying to do this -- in detail -- will help you to get better suggestions and solutions (or alternative ways of addressing your actual problem).
-ASB: https://www.BrainWaveCC.com/

Lazarus v4.3.0.0 (bcf314a670) / FreePascal v3.2.3-46-g77716a79dc (aka fixes)
(Windows 64-bit install w/Win32 and Linux on ARM and x64 cross-compilers via FpcUpDeluxe)

My Systems: Windows 10/11 Pro x64 (Current)

Jake012345

  • Sr. Member
  • ****
  • Posts: 270
  • Knowledge is the key
Re: Uncloseable App.
« Reply #9 on: June 12, 2020, 01:32:33 am »
Maybe Useless!


Little bit complicated...
So you can make a program what starts on startup and auto load in all files in the folder.
And now the files are unmodifiable until the program runs. (On the OnClose action, you can make a restart procedure (for the task manager))
The Reader application can send data for this application to motivate that to makes the current file free.

I hope it can be worked!

In the linked Topic

Jake012345

  • Sr. Member
  • ****
  • Posts: 270
  • Knowledge is the key
Re: Uncloseable App.
« Reply #10 on: June 12, 2020, 01:45:47 am »
Here's the 'first bone':

Raul_ES

  • Full Member
  • ***
  • Posts: 183
  • My interests: Healthcare & Computers
    • My Linkedin Profile, you can add me to stay in contact.
Re: Uncloseable App.
« Reply #11 on: June 12, 2020, 01:50:49 am »
And sure I want to run it without window, (at most with TrayIcon) so the taskmanager is the biggest problem.

form the topic:
Quote
if someone using the same computer corrupted the files either by accident or on purpose.
So not enough a warning that says 'Hey! that's not yours so keep away yourself!'.

Maybe you want to create a system daemon or a Windows service running in the background? Only the administrator or certain allowed users will be able to terminate the process.
You then can create a visual app (or a small tray icon) to communicate with such service.
Pharmacy + Chemistry + Biology + Healthcare + Computing

If you have any interest or project related with these areas feel free to contact me!

RAW

  • Hero Member
  • *****
  • Posts: 871
Re: Uncloseable App.
« Reply #12 on: June 12, 2020, 01:52:24 am »
Quote
...now the files are unmodifiable until the program runs.
Those things should be handled with a user account, put the files inside a folder that can be read but not changed by the user ....

@Raul_ES
this is easier:
Code: Pascal  [Select][+][-]
  1. if ServerOn Then
  2. if Not ServerOn Then

Raul_ES

  • Full Member
  • ***
  • Posts: 183
  • My interests: Healthcare & Computers
    • My Linkedin Profile, you can add me to stay in contact.
Re: Uncloseable App.
« Reply #13 on: June 12, 2020, 01:59:34 am »
Easier and cleaner  ;)

thanks RAW
Pharmacy + Chemistry + Biology + Healthcare + Computing

If you have any interest or project related with these areas feel free to contact me!

Raul_ES

  • Full Member
  • ***
  • Posts: 183
  • My interests: Healthcare & Computers
    • My Linkedin Profile, you can add me to stay in contact.
Re: Uncloseable App.
« Reply #14 on: June 12, 2020, 02:03:13 am »
Yeah but he's trying to force the app to stay alive no matter what.. That type of program is not welcomed where I come from.

you mean even if a root user or administrator kills the app process?  :(
Pharmacy + Chemistry + Biology + Healthcare + Computing

If you have any interest or project related with these areas feel free to contact me!

 

TinyPortal © 2005-2018