Tell me how to distinguish between the execution of commands, to first perform the removal of the key in the registry, then start the external application, after which the parameters should return to the registry, and the application will exit.
This is necessary so that the command to delete the registry key has time to perform actions before opening the external application, and the application has time to start before the registry settings return to their original state.
How it works - the file is transferred to the application, the application reads the file arguments, then by code:
if (args.Any()) { key = Registry.LocalMachine.OpenSubKey("MyAapp\\BranchReg", true); key.DeleteValue("KeyReg", false); key.Close(); Process.Start(args[0]); key = Registry.LocalMachine.CreateSubKey("MyAapp\\BranchReg"); key.SetValue("KeyReg", ""); key.Close(); Application.Exit(); }
WaitForInputIdle. Also see stackoverflow.com/q/6390030/5045688 - Alexander Petrov