views:

92

answers:

5

I want to make .exe for desktop application which can only used once in whole life.Nobody can run it twice.

+1  A: 

Delete itself as it exits?

Martin
Better yet, delete once it's completely loaded. That's pretty much the only way I'd say.
tdammers
Couldn't the exe be copied before first run, so the backup would always be available?
Rox
That is not an answer... voted down...-1 from me
tommieb75
A: 

What you are talking about is a single instance application that can start up, and no other copy can run - the single instance start up code is based on creating a mutex, and if another copy is run, it checks to see if the mutex is allocated, if it is, it bails out and exits immediately. Have a look at this article on CodeProject that does exactly what you're looking for.

tommieb75
"only used once in whole life. Nobody can run it twice." - from this I understood that he doesn't want the program to be started again after the first run.
Rox
@Rox: that is the idea of using a global mutex allocated by the system...once it's allocated, that's it... no other copy can run...
tommieb75
The "in whole life" suggests this isn't quite what the OP intends.
Marc Gravell
@Marc: hmmmm the computer running on infinite energy powered by dilithium crystals?
tommieb75
@tommieb75: as I understood, he wants the user to be able to use the program only once: start, do stuff, close the app and that's it. If he tried to start it again after closing it, he wouldn't be able to. That's what I tried to say with the first comment.
Rox
A: 

It's possible to use a combination of DPAPI calls (ProtectedData Class) to push a value into the registry to check for a second time, or alternatively encode a value on first run and check the result matches the machine you intend it to be run on (and exit if not).

See DataProtectionScope.LocalMachine. The result of the protected data will be almost always different per machine, so this works as a specific-machine check.

Codesleuth
+5  A: 

You can not do that reliably.

You may try simple stuff like writing a magic key in the registry or storing a magic file somewhere, but simple tools like Process Monitor will show your magic markers to anyone with Google skills.

You may try to delete the .exe when it is terminating, but if the user makes a copy before they execute your file, you loose again.

You may write a root-kit that prevents the system from launching your application twice, but that is not very nice and it can be detected and circumvented too.

You may create an online service where your application needs check for a one time license to execute, but that can be cracked and you will get a big mess keeping track of one time licenses.

But in the end, if someone really wants to run your application more than once they will figure out how to do it.

How much protection do you want?

Albin Sunnanbo
A: 

You could create a registry key. If the key exists abort execution.

Grif