T
T
TechNOIR2018-08-14 10:04:39
C++ / C#
TechNOIR, 2018-08-14 10:04:39

C#. How to self-destruct a program when a condition is not met?

Good afternoon.
I have conditions in the script.
It is necessary that, under the condition "This is not the right disk," the file that starts up is deleted. That is, the current exe.
But it fails accordingly. because it's busy. How can this problem be solved? Thank you!

if (!curdir.StartsWith("P")){
                Console.WriteLine("Это не тот диск");
                string script_name = System.Reflection.Assembly.GetEntryAssembly().Location;
                Console.WriteLine(script_name);
                File.Delete(script_name);
                Thread.Sleep(20000);
            }
            else
            {
                Console.WriteLine("Это тот диск!");
                Thread.Sleep(20000);
            }

Answer the question

In order to leave comments, you need to log in

3 answer(s)
R
Roman, 2018-08-14
@TechNOIR

Self-deleting-after-using-program

A
Artem, 2018-08-14
@devspec

We need a second process that will delete the first one. Nothing else.

#
#, 2018-08-14
@mindtester

curious ..
- you can create a process in memory not from a file , and transfer control to it
- why are you not satisfied with simply refusing to work? )) .. let's start with the fact that no one forbids a non-accredited user from having a copy in downloads (etc) .. we end up saying that without the use of a dotfuscator (at least a free one), any shkolota, with sufficient enthusiasm, will cure your "protection "
ps There is no point in deleting if the original is not protected, at least with a dotfuscator. if it is protected - it is hardly worth bothering like that, it is enough to refuse to work
pps was also thinking about bindings - I like the idea of ​​binding to a system or user SID more. guaranteed unique, but you can allow the user to change the disk to a larger or faster one .. and even change the computer .. (within the same network, Windows itself will start squealing when you try to duplicate the OS SID, but the user SID ... within the corporate AD - yes, it can be whiter than replicated) (but who forbids checking a couple of seeds at once?)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question