How do I make sure only one instance of my program can be executed?

后端 未结 6 561
旧时难觅i
旧时难觅i 2021-01-07 01:17

I want my program, a Java executable .jar, to be run just once. I made a program but now I want users not to be able to open more than one instance ....thanks for your time.

6条回答
  •  悲哀的现实
    2021-01-07 01:48

    You could programmatically extract the jar file, http://www.devx.com/tips/Tip/22124, the update one file that will prevent the application from running anymore, then rejar it.

    The other option would be to just delete some critical class from the jar file, but neither of these will prevent it from being run again, as they can copy the jar file.

    You can't update a registry as there isn't a platform independent way to do that.

提交回复
热议问题