Tell me how to link the password protection for the arguments? The arguments need to be protected by a password, let's say we enter C:\>app.exe password /off and the C:\>app.exe password /off is first sent, if it is correct, the /off command is executed (all in one line).
Maybe there is an opportunity to somehow embed a password to the name of the arguments? Since it is necessary for the application shortcut to contain both a password and arguments for using the task scheduler.
The password itself will be stored in a text document, see the code example below.
Clarification of the question: how to insert a separate code for the password into the main code?
The main code of the WinForm C # application
static class Program { [DllImport("kernel32.dll")] private static extern bool AttachConsole(int procid); /// <summary> /// Главная точка входа для приложения. /// </summary> [STAThread] static void Main(string[] args) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); var form = new Form1(); bool needRun = true; AttachConsole(-1); string outputFmt = "Команда {0} выполнена" + "\n" + "Для продолжения нажмите любую клавишу . . ."; List<string> cmds = new List<string>(); foreach (string arg in args) { if (args.Contains("/?")) { form.Check00(); needRun = false; } switch (arg) { case "/on": form.Check01(); needRun = false; break; case "/off": form.Check02(); needRun = false; break; } cmds.Add(arg); } Console.WriteLine(outputFmt, string.Join(" ", cmds.ToArray())); if (needRun) { Application.Run(form); } } } Separate password protection code (which cannot be linked):
private class ConsolePassword { public ConsolePassword() { string password, password1 = string.Empty; password = Console.ReadLine(); using (StreamReader sr = new StreamReader(File.Open("C:\\1.txt", FileMode.Open))) { password1 = sr.ReadLine(); sr.Close(); } if (password == password1) { Console.WriteLine("Доступ разрешен."); } else { Console.WriteLine("Доступ запрещен."); } } }
ConsolePasswordmethodConsolePasswordthat itConsolePasswordentered password as an argument and checks for its correctness. It seems to me that it would be better to call thepassword1variablereal_password. It's not entirely clear what the question is - mymedia