5

How to prevent users from closing my executable(exe) application using task manager despite of their privileges?

I usually use Lunch4j to convert my excecutable jar file to .exe file, but alt+f4 is enough to close the program.

My question is, is there any thing, programmatically in java before wrapping as exe, or after that in system configurations, that I can do to make it unclosable "access denied" or to mark the application as a system service if that is useful in this case?

Thank you

TiyebM
  • 2,684
  • 3
  • 40
  • 66
  • possible duplicate of [How can I prevent a user from closing my C# application?](http://stackoverflow.com/questions/4655810/how-can-i-prevent-a-user-from-closing-my-c-sharp-application) – Izzy Apr 23 '15 at 10:33
  • What seems to be missing since you awarded a bounty... – ZF007 Dec 19 '18 at 15:10

2 Answers2

10

Generally speaking, there's no way to stop your process from being terminated by a user with permission to do so.

So, if the user is not an administrator it would suffice to run the process in a different user context (eg run it as a service).

As mentioned in this article "you can not, and should not, attempt to stop an Administrator from killing your process or stopping your service".

That being said, you can adjust your process’ access control list to prevent users from killing it.

It is a good practice to explicitly give the necessary rights and not let everybody (user or application) have administrative rights in your system.

Using this practice you can easily prevent nearly everyone from terminating your process.

You can find here more information about the Microsoft Windows security model and options about securing your application against the world.

Panayotis
  • 1,743
  • 1
  • 17
  • 30
  • 1
    `You can adjust your process’ access control list to prevent users from killing it`. A great article Thanks. – TiyebM Apr 23 '15 at 11:33
0

You might want to change from Lunch4j compiler to "Yet Another Java Service Wrapper". This one can be found here. Lunch4j has no service options. Be sure to bundle the JRE (Java Runtime Environment) because then its a standalone program.

Check out the OS USER options. In short:

On MS-windows, per default, if not configured otherwise services are started under the SYSTEM account. On windows we are using the function CreateProcessAsUserW . This requires the...

SE_ASSIGNPRIMARYTOKEN_NAME and SE_INCREASE_QUOTA_NAME user rights.

We are not using CreateProcessWithLogonW because the command line length is limited to 1024 chars, which may be too short for java applications. The password is defined by the property wrapper.ntservice.password. If the password is defined in the configuration file then it is not visible in the command line of the application nor in the windows services GUI .

Edit (based on changes in question):

Go have a look here for the use of sc.exe as promoted to make your executable a service. You run the program from the command line.

ZF007
  • 3,708
  • 8
  • 29
  • 48