Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static Dictionary<string, string> GetProcs(string server, string sessID)
- {
- SecureString ss = CreatePW();
- ProcessStartInfo startInfo = new ProcessStartInfo("cmd", "/C tasklist /S " + server + " /FI "SESSION eq " + sessID + "" /FO CSV /NH")
- {
- WindowStyle = ProcessWindowStyle.Hidden,
- UseShellExecute = false,
- RedirectStandardOutput = true,
- RedirectStandardError = true,
- CreateNoWindow = true,
- WorkingDirectory = @"C:windowssystem32",
- Verb = "runas",
- Domain = "BARDOM1",
- UserName = "zzkillcitrix",
- Password = ss
- };
- List<string> procList = new List<string>();
- Process proc = Process.Start(startInfo);
- proc.OutputDataReceived += (x, y) => procList.Add(y.Data);
- proc.BeginOutputReadLine();
- proc.WaitForExit();
- // Create a new ditionary ...
- Dictionary<string, string> procDict = new Dictionary<string, string>();
- for (int i = 0; i < procList.Count - 1; i++)
- {
- if (procDict.ContainsKey(procList[i].Split(',')[0].Trim('"')))
- {
- // Do nothing
- }
- else
- {
- procDict.Add(procList[i].Split(',')[0].Trim('"'), procList[i].Split(',')[1].Trim('"'));
- }
- }
- return procDict;
- }
- public static List<Proc> GetProcList(Session session)
- {
- // Get the current tasks
- List<string> processQueryResult = TaskList(session);
- List<Proc> procList = new List<Proc>();
- foreach (var processDetails in processQueryResult)
- {
- // Only create the Proc if the process is in the 'valid' array ...
- // Get the procname
- string procName = processDetails.Split(',')[0].Trim('"').ToUpper();
- // Make sure it's position is not -1 ...
- int pos = Array.IndexOf(MyGlobals.ProcArray, procName);
- if (pos > -1)
- {
- int procId = Int32.Parse(processDetails.Split(',')[1].Trim('"'));
- Proc p = new Proc(procName, procId, session.ServerName, session.ID);
- procList.Add(p);
- SupportMI.Trace = "--adding" + p.Name + "--";
- }
- }
- return procList;
- }
- private static List<string> TaskList(Session session)
- {
- string cmdIn = "tasklist /S " + session.ServerName + " /FI "SESSION eq " + session.ID + "" /FO CSV /NH";
- List<string> cmdOut = Cmd.StdOutAdminList(cmdIn);
- return cmdOut;
- }
- public static List<string> StdOutAdminList(string args)
- {
- List<string> cmdOut = new List<string>();
- SecureString ss = pw();
- ProcessStartInfo startInfo = new ProcessStartInfo("cmd", "/C " + args)
- {
- WindowStyle = ProcessWindowStyle.Hidden,
- UseShellExecute = false,
- RedirectStandardOutput = true,
- RedirectStandardError = true,
- CreateNoWindow = true,
- WorkingDirectory = @"C:windowssystem32",
- Verb = "runas",
- Domain = "BARDOM1",
- UserName = "zzkillcitrix",
- Password = ss
- };
- cmdOut = ExecuteListCommand(startInfo);
- return cmdOut;
- }
- private static List<string> ExecuteListCommand(ProcessStartInfo startInfo)
- {
- List<string> procList = new List<string>();
- Process p = Process.Start(startInfo);
- p.OutputDataReceived += (x, y) => procList.Add(y.Data);
- p.BeginOutputReadLine();
- p.WaitForExit();
- return procList;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement