privatevoidRunCLIjobsOnLocal(stringarguments,intWaitTimePerCommand){varpsi=newProcessStartInfo();psi.CreateNoWindow=true;//This hides the dos-style black window that the command prompt usually showspsi.FileName=@"cmd.exe";psi.Arguments="/C "+arguments;psi.RedirectStandardOutput=true;psi.RedirectStandardInput=true;psi.RedirectStandardError=true;psi.UseShellExecute=false;varsspw=newSecureString();foreach(varcinpassword){sspw.AppendChar(c);}psi.Domain=domain;psi.UserName=userName;psi.Password=sspw;psi.WorkingDirectory=@"C:\";using(Processprocess=newProcess()){try{process.StartInfo=psi;process.Start();varprocId=process.Id;stringowner=GetProcessOwner(procId);// Synchronously read the standard output of the spawned process. StreamReaderreader=process.StandardOutput;stringoutput=reader.ReadToEnd();reader=process.StandardError;stringerror=reader.ReadToEnd();if(error.Length>0)process.WaitForExit();}catch(Exceptione){log.Error(e.Message+"\n"+e.StackTrace);}}}privatestringGetProcessOwner(intprocessId){stringquery="Select * From Win32_Process Where ProcessID = "+processId;ManagementObjectSearchersearcher=newManagementObjectSearcher(query);ManagementObjectCollectionprocessList=searcher.Get();foreach(ManagementObjectobjinprocessList){string[]argList=newstring[]{string.Empty,string.Empty};intreturnVal=Convert.ToInt32(obj.InvokeMethod("GetOwner",argList));if(returnVal==0){returnargList[1]+"\\"+argList[0];}}return"NO OWNER";}