Ejemplo n.º 1
0
        /// <summary>
        /// Entry points of the program.
        /// </summary>
        /// <param name="args">Arguments from the ZombifyMe library.</param>
        /// <returns>0 if the monitored process exited normally, 1 if it was restarted, or a negative value in case of error.</returns>
        public static int Main(string[] args)
        {
            Thread.Sleep(TimeSpan.FromSeconds(5));

            // Check arguments; They should be valid since only ZombifyMe is starting us.
            if (args == null || args.Length < 8)
            {
                return(-1);
            }

            // Read the ID of the process to monitor.
            if (!int.TryParse(args[0], out int ProcessId))
            {
                return(-2);
            }

            string ProcessExePath   = args[1];
            string ProcessArguments = args[2];
            string ClientName       = args[3];

            try
            {
                // Open the cancel event. This event uses two unique names, one for the ZombifyMe, the other from the client.
                using EventWaitHandle? CancelEvent = EventWaitHandle.OpenExisting(SharedDefinitions.GetCancelEventName(ClientName));

                // Read the delay, in ticks.
                if (!long.TryParse(args[4], out long DelayTicks))
                {
                    return(-4);
                }

                TimeSpan Delay = TimeSpan.FromTicks(DelayTicks);
                if (DelayTicks < 0)
                {
                    return(-4);
                }

                // Read messages. They can be empty.
                string WatchingMessage = args[5];
                string RestartMessage  = args[6];

                // Read the flags, as a set of bits.
                if (!int.TryParse(args[7], out int FlagsValue))
                {
                    return(-5);
                }
                if (FlagsValue == -1)
                {
                    return(-5);
                }
                Flags Flags = (Flags)FlagsValue;

                // Display the begin message if requested.
                if (WatchingMessage.Length > 0)
                {
                    TaskbarBalloon.Show(WatchingMessage, TimeSpan.FromSeconds(5), TimeSpan.FromSeconds(1));
                }

                MonitorProcess(ProcessId, ProcessExePath, ProcessArguments, CancelEvent, Delay, RestartMessage, Flags, out bool IsRestarted);

                return(IsRestarted ? 1 : 0);
            }
            catch
            {
                return(-3);
            }
        }
Ejemplo n.º 2
0
        private static void Monitor(string[] args)
        {
            bool IsMonitorCancel = args.Length > 1 && args[1] == "cancel";
            bool IsMonitorWait   = args.Length > 1 && args[1] == "cancel";

#if NET48
            int ProcessId = Process.GetCurrentProcess().Id;
#else
            int ProcessId = Environment.ProcessId;
#endif

            Console.WriteLine($"set TEST_ZOMBIFY_PROCESS_ID={ProcessId}\r\n");
            using EventWaitHandle CancelEvent = new EventWaitHandle(false, EventResetMode.ManualReset, SharedDefinitions.GetCancelEventName("Coverage"));

            Thread.Sleep(TimeSpan.FromSeconds(5));

            if (IsMonitorCancel)
            {
                CancelEvent.Set();
                Thread.Sleep(TimeSpan.FromSeconds(5));
            }

            if (IsMonitorWait)
            {
                Thread.Sleep(TimeSpan.FromSeconds(5));
            }
        }