Example #1
0
        // Overloaded method used to store the threads ID and what file gets opened when CustomRun is ran.
        public void RunCmd(string target, string fileName, LabClient client)
        {
            var pID = "";
            using (var process = new Process())
            {
                process.StartInfo.FileName = target;
                process.StartInfo.CreateNoWindow = true;
                process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
                process.StartInfo.UseShellExecute = false;
                process.StartInfo.RedirectStandardOutput = true;
                process.StartInfo.RedirectStandardError = true;
                process.StartInfo.RedirectStandardInput = true;

                var output = new StringBuilder();
                var error = new StringBuilder();

                using (var outputWaitHandle = new AutoResetEvent(false))
                using (var errorWaitHandle = new AutoResetEvent(false))
                {
                    process.OutputDataReceived += (sender, e) =>
                    {
                        if (e.Data == null)
                        {
                            outputWaitHandle.Set();
                        }
                    };
                    process.ErrorDataReceived += (sender, e) =>
                    {
                        if (e.Data == null)
                        {
                            errorWaitHandle.Set();
                        }
                        else
                        {
                            if (e.Data.Contains("ID"))
                            {
                                var index = e.Data.IndexOf("ID");
                                var temp = e.Data.Substring(index, e.Data.Length - index - 1);
                                pID = temp.Substring(3, temp.Length - 3);

                                var cp1 = new CompAndProcesses();
                                cp1.computer = client;
                                cp1.processName = fileName;
                                cp1.threadID = pID;
                                CompAndProcesseses.Add(cp1);

                                //Send a message to LabClients, if LabClients puts a respond message in the replyqueue.
                                var path = "FormatName:Direct=OS:" + client.ComputerName.ToLower() + "\\private$\\requestqueue";
                                MessageQueue rmTmsq = new MessageQueue(path);

                                System.Messaging.Message msg = new System.Messaging.Message("The purpose is to check whenever a process has been started");

                                MessageQueueTransaction trans = new MessageQueueTransaction();

                                try
                                {
                                    trans.Begin();
                                    rmTmsq.Send(msg, pID, trans);
                                    trans.Commit();
                                }
                                catch (Exception ee)
                                {
                                    throw ee;
                                }
                                finally
                                {
                                    trans.Dispose();
                                }
                            }
                            error.AppendLine(e.Data);
                        }
                    };
                    try
                    {
                        process.Start();
                    }
                    catch (Exception e)
                    {

                    }

                    process.BeginOutputReadLine();
                    process.BeginErrorReadLine();
                    var timeout = 15000;
                    if (process.WaitForExit(timeout) &&
                        outputWaitHandle.WaitOne(timeout) &&
                        errorWaitHandle.WaitOne(timeout))
                    {
                        //Could type some Process.Exist code here but it aint needed.

                        Debug.Write(output);
                        Debug.Write("ERROR:" + error);
                    }
                }
            }
        }
Example #2
0
        // Overloaded method used to store the threads ID and what file gets opened when CustomRun is ran.
        public void RunCmd(string target, string fileName, LabClient client)
        {
            var s = "";
            using (var process = new Process())
            {
                process.StartInfo.FileName = target;
                process.StartInfo.CreateNoWindow = true;
                process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
                process.StartInfo.UseShellExecute = false;
                process.StartInfo.RedirectStandardOutput = true;
                process.StartInfo.RedirectStandardError = true;
                process.StartInfo.RedirectStandardInput = true;

                var output = new StringBuilder();
                var error = new StringBuilder();

                using (var outputWaitHandle = new AutoResetEvent(false))
                using (var errorWaitHandle = new AutoResetEvent(false))
                {
                    process.OutputDataReceived += (sender, e) =>
                    {
                        if (e.Data == null)
                        {
                            outputWaitHandle.Set();
                        }
                    };
                    process.ErrorDataReceived += (sender, e) =>
                    {
                        if (e.Data == null)
                        {
                            errorWaitHandle.Set();
                        }
                        else
                        {
                            if (e.Data.Contains("ID"))
                            {
                                var index = e.Data.IndexOf("ID");
                                var temp = e.Data.Substring(index, e.Data.Length - index - 1);
                                s = temp.Substring(3, temp.Length - 3);

                                Debug.Write("TEST: ", s);
                                var cp1 = new CompAndProcesses();
                                cp1.computer = client;
                                cp1.processName = fileName;
                                cp1.threadID = s;
                                CompAndProcesseses.Add(cp1);
                            }
                            error.AppendLine(e.Data);
                        }
                    };

                    process.Start();

                    process.BeginOutputReadLine();
                    process.BeginErrorReadLine();
                    var timeout = 15000;
                    if (process.WaitForExit(timeout) &&
                        outputWaitHandle.WaitOne(timeout) &&
                        errorWaitHandle.WaitOne(timeout))
                    {
                        //Could type some Process.Exist code here but it aint needed.

                        Debug.Write(output);
                        Debug.Write("ERROR:" + error);
                    }
                }
            }
        }
Example #3
0
 public void InitProcList(List<LabClient> clients)
 {
     procList = new List<CompAndProcesses>();
     foreach (var client in clients)
     {
         var ComProc = new CompAndProcesses();
         ComProc.computer = client;
         procList.Add(ComProc);
     }
 }