public static void ExecPythonA(string path, string args, ExecCmdWindowOption execCmdOption, bool popupOutput, ProcessAccountInfo processAccountInfo)
 {
     try
     {
         if (!FileHelper.IsFileExisting(PythonExecPath))
         {
             throw new ArgumentException("Python exec file does not exist!");
         }
         if (!System.IO.File.Exists(path))
         {
             throw new ArgumentException("File: '" + path + "' does not exist!");
         }
         var inputStr = PythonExecPath + " " + path + " " + args;
         ExecCmdA(inputStr, execCmdOption, popupOutput, processAccountInfo);
     }
     catch (Exception ex)
     {
         throw new ArgumentException("\n>> " + TypeName + ".RunPython Error: " + ex.Message);
     }
 }
        public static string ExecCmd(string inputStr, ExecCmdWindowOption execCmdOption, ExecCmdOutputOption outputOption, ProcessAccountInfo processAccountInfo)
        {
            if (string.IsNullOrEmpty(inputStr))
            {
                return("");
            }

            var process = new Process();

            process.StartInfo.FileName = "cmd.exe";
            //process.StartInfo.Arguments = args;
            process.StartInfo.UseShellExecute        = false;
            process.StartInfo.RedirectStandardInput  = true;
            process.StartInfo.RedirectStandardOutput = true;
            process.StartInfo.RedirectStandardError  = true;
            process.StartInfo.WindowStyle            = ProcessWindowStyle.Normal;
            //process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;//does not work, the windows shown or hidden depends on  "process.StartInfo.CreateNoWindow"

            var execCmdMode = ExecCmdMode.AsyncWindow;

            if (execCmdOption == ExecCmdWindowOption.ShowWindow)
            {
                execCmdMode = ExecCmdMode.AsyncWindow;
            }
            else if (execCmdOption == ExecCmdWindowOption.NoWindow & outputOption == ExecCmdOutputOption.None)
            {
                execCmdMode = ExecCmdMode.NoWindow;
            }
            else if (execCmdOption == ExecCmdWindowOption.NoWindow & outputOption != ExecCmdOutputOption.None)
            {
                execCmdMode = ExecCmdMode.NoWindowWithOutput;
            }
            else if (execCmdOption == ExecCmdWindowOption.BlankWindow & outputOption == ExecCmdOutputOption.None)
            {
                execCmdMode = ExecCmdMode.BlankWindow;
            }
            else if (execCmdOption == ExecCmdWindowOption.BlankWindow & outputOption != ExecCmdOutputOption.None)
            {
                execCmdMode = ExecCmdMode.BlankWindowWithOutput;
            }

            var returnOutput = false;

            if (execCmdMode == ExecCmdMode.AsyncWindow)
            {
                inputStr = "start " + _startBatPath + " " + inputStr;
                process.StartInfo.CreateNoWindow = true;
                returnOutput = false;
            }
            else if (execCmdMode == ExecCmdMode.SyncWindow)
            {
                inputStr = "start " + _startBatPath + " " + inputStr;
                process.StartInfo.CreateNoWindow = true;
                returnOutput = true;
            }
            else if (execCmdMode == ExecCmdMode.NoWindow)
            {
                process.StartInfo.CreateNoWindow = true;
                returnOutput = false;
            }
            else if (execCmdMode == ExecCmdMode.NoWindowWithOutput)
            {
                process.StartInfo.CreateNoWindow = true;
                returnOutput = true;
            }
            else if (execCmdMode == ExecCmdMode.BlankWindow)
            {
                process.StartInfo.CreateNoWindow = false;
                //when CreateNoWindow = false, popup a empty cmd window, no any exec result appears.
                returnOutput = false;
            }
            else if (execCmdMode == ExecCmdMode.BlankWindowWithOutput)
            {
                process.StartInfo.CreateNoWindow = false;
                returnOutput = true;
            }
            if (processAccountInfo != null)
            {
                process.StartInfo.Domain   = processAccountInfo.Domain;
                process.StartInfo.UserName = processAccountInfo.UserName;
                var pw = new System.Security.SecureString();
                foreach (var v in processAccountInfo.Password.ToCharArray())
                {
                    pw.AppendChar(v);
                }
                process.StartInfo.Password = pw;
            }
            try
            {
                process.Start();
                //process.StandardInput.WriteLine("cd " + @"C:\windows\system32");
                process.StandardInput.WriteLine(inputStr);
                process.StandardInput.WriteLine("exit");
                var outputStr = "";
                if (returnOutput)
                {
                    outputStr = process.StandardOutput.ReadToEnd();//When use 'start' to start a real new window, the  Output is on the new window, not this empty window. so if you want a return output , don't use 'start'
                }
                process.WaitForExit();
                process.Close();
                return(outputStr);
            }

            catch (Exception ex)
            {
                throw new ArgumentException("\n>> " + TypeName + ".ExecCmd Error: " + ex.Message);
            }
        }
        public static void ExecBat(bool raiseUacLevel, string path, string args, ExecCmdWindowOption execCmdWindowOption, bool popupOutput, ProcessAccountInfo processAccountInfo)
        {
            if (string.IsNullOrEmpty(path))
            {
                throw new ArgumentException("File: '" + path + "' does not exist!");
            }
            var inputStr     = path + " " + args;
            var execFilePath = raiseUacLevel ? _execXcmdAFilePath : _execXcmdFilePath;

            inputStr = popupOutput ? execFilePath + " /k " + inputStr : execFilePath + " " + inputStr;
            ExecCmd(inputStr, execCmdWindowOption, ExecCmdOutputOption.None, processAccountInfo);
        }
        public static void Run(bool raiseUacLevel, string path, string args, bool isSync, ProcessAccountInfo processAccountInfo)
        {
            var process = new Process();

            if (!System.IO.File.Exists(path))
            {
                throw new ArgumentException("File: '" + path + "' does not exist!");
            }

            var path1 = raiseUacLevel ? _execCmdAFilePath : path;

            process.StartInfo.FileName = path1;
            var args1 = raiseUacLevel ? path + " " + args : args;

            if (!string.IsNullOrEmpty(args1))
            {
                process.StartInfo.Arguments = args1;//to "explorer.exe", args="D:\\Readme.txt"; to "iexplore.exe",args=http://www.baidu.com
            }
            if (raiseUacLevel)
            {
                process.StartInfo.CreateNoWindow = true;
            }
            process.StartInfo.UseShellExecute = false;
            if (processAccountInfo != null)
            {
                process.StartInfo.Domain   = processAccountInfo.Domain;
                process.StartInfo.UserName = processAccountInfo.UserName;
                var pw = new System.Security.SecureString();
                foreach (var v in processAccountInfo.Password.ToCharArray())
                {
                    pw.AppendChar(v);
                }
                process.StartInfo.Password = pw;
            }
            try
            {
                process.Start();
                if (isSync)
                {
                    process.WaitForExit();
                    process.Close();
                }
            }
            catch (Exception ex)
            {
                throw new ArgumentException("\n>> " + TypeName + ".Run Error: " + ex.Message);
            }
        }
 public static void ExecCmdA(string inputStr, ExecCmdWindowOption execCmdWindowOption, bool popupOutput, ProcessAccountInfo processAccountInfo)
 {
     if (string.IsNullOrEmpty(inputStr))
     {
         return;
     }
     inputStr = popupOutput ? _execCmdAFilePath + " /k " + inputStr : _execCmdAFilePath + " " + inputStr;
     ExecCmd(inputStr, execCmdWindowOption, ExecCmdOutputOption.None, processAccountInfo);
 }