using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Diagnostics; using Microsoft.VisualBasic; using System.Windows.Forms; namespace romrestarter { class Program { static void Main(string[] args) { pause(2); var childPidToParentPid = GetAllProcessParentPids(); int currentProcessId = Process.GetCurrentProcess().Id; int parentPid = childPidToParentPid[currentProcessId]; Process parent = Process.GetProcessById(parentPid); parent.Kill();// we kill our parent xD Process child = System.Diagnostics.Process.Start("micromacro.exe"); pause(3); Interaction.AppActivate(child.Id); // arg 1 directory"name/" arg 2 path arg3 profile ar4 character (optional) arg5 retpath if (args.Length == 4) { SendKeys.Send("" + args[0] + "bot.lua path:" + args[1] + " profile:" + args[2] + " character:" + args[3] + ""); } else { if (args.Length == 5) { SendKeys.Send("" + args[0] + "bot.lua path:" + args[1] + " profile:" + args[2] + " character:" + args[3] + " retpath:" + args[4] + ""); } else { System.Console.WriteLine("Please read the docu your input is incorect"); } } SendKeys.Send("{ENTER}"); // program end } public static Dictionary GetAllProcessParentPids() { var childPidToParentPid = new Dictionary(); var processCounters = new SortedDictionary(); var category = new PerformanceCounterCategory("Process"); // As the base system always has more than one process running, // don't special case a single instance return. var instanceNames = category.GetInstanceNames(); foreach(string t in instanceNames) { try { processCounters[t] = category.GetCounters(t); } catch (InvalidOperationException) { // Transient processes may no longer exist between // GetInstanceNames and when the counters are queried. } } foreach (var kvp in processCounters) { int childPid = -1; int parentPid = -1; foreach (var counter in kvp.Value) { if ("ID Process".CompareTo(counter.CounterName) == 0) { childPid = (int)(counter.NextValue()); } else if ("Creating Process ID".CompareTo(counter.CounterName) == 0) { parentPid = (int)(counter.NextValue()); } } if (childPid != -1 && parentPid != -1) { childPidToParentPid[childPid] = parentPid; } } return childPidToParentPid; } static void pause(double sec) { Console.WriteLine(+sec + " sec pause \r\n"); double time = DateTime.Now.Ticks + (sec * 10000000); while (DateTime.Now.Ticks <= time) { } } } }