private static void Main(string[] args) { var log = SimpleLogManager.GetLogger(typeof(Program), "Main"); log.Info(string.Format("Command line: {0} {1}", Process.GetCurrentProcess().ProcessName, string.Join(" ", args))); InjectorParameters parameters = null; try { parameters = new InjectorParameters(args); } catch (Exception ex) { log.Error(string.Format( "Wrong command-line arguments: {0}.\r\n{1}", ex.Message, ex)); return; } try { Injector.Launch(parameters); // Make sure we were injected; it not, retry with the main window handle. var process = GetProcessFromWindowHandle(parameters.WindowHandle); if (process != null && !CheckInjectedStatus(process) && process.MainWindowHandle != parameters.WindowHandle) { log.Debug("Could not inject with current handle... retrying with MainWindowHandle"); parameters.WindowHandle = process.MainWindowHandle; Injector.Launch(parameters); CheckInjectedStatus(process); } } catch (Exception ex) { log.Error(string.Format( "There was an error during the injection process: {0}.\r\n{1}", ex.Message, ex)); return; } log.Debug(new string('-', 120)); }