Does the application have / on / off arguments? How can I protect the application from running them?
No Or do you allow the use of arguments or not.
Is there a way to create a certain file with a bunch of characters, without which the application does not work?
There is. You write the code inside the program to check the validity of a file (not necessarily text, it can be a bit file) and if it does not match or the file is missing, close the program with the corresponding error / message.
And how can this file be modified using the application form?
And what is it for?
Or, something like binding an application to a hardware or activating by keys, in order to protect it from itself.
The simplest binding to the gland is realized through the generation of an activation key from the mac address. Mac address is always unique on every computer. Accordingly, you take the first of poppies, somehow you process it and keep the key by which you can activate your application. This is done quite simply: here on the console screen will give you a generated key tied to the hardware:
class Program { static void Main(string[] args) { var mac = GetMacAdress(); Console.WriteLine(GetNumbersFromMac(mac) + GetMirroredCharsFromMac(mac)); } private static string GetMacAdress() { return NetworkInterface.GetAllNetworkInterfaces().Where(nic => nic.OperationalStatus == OperationalStatus.Up) .Select(nic => nic.GetPhysicalAddress().ToString()).FirstOrDefault(); } private static string GetNumbersFromMac(string mac) { string tmpDigit = Regex.Replace(mac, @"[^0-9]+", String.Empty); string getPositionNumber = string.Empty; foreach (char number in tmpDigit) { getPositionNumber += number * 129 / 258; } return getPositionNumber; } private static string GetMirroredCharsFromMac(string mac) { string tmpLetter = Regex.Replace(mac, @"[^AZ]+", String.Empty); string getMirrored = string.Empty; for (int i = tmpLetter.Length; i > 0; i--) { getMirrored += (tmpLetter[i - 1]); } return getMirrored; } }
Accordingly, if the key is entered correctly, you need to make an entry in the registry or create the same registry file based on the key in the program folder ... And the next time you start it, check for the presence of a key in the registry / registry file. If there are none, simply make a request to enter an activation key or close the program.
console.exe /offin the command line and the application is disabled, you need to enter such a command to check for a password or another method - Vitokhvif (args.Contains("/off")) { if (!AskAndVerifyPassword()) return; }if (args.Contains("/off")) { if (!AskAndVerifyPassword()) return; }? - VladD