Moin,
Vielleicht könnt ihr mir schnell mal helfen
Ich möchte einen schnellen Überblick auf die Benutzersitzungen unserer TerminalServer.
Wenn ich das auf der Konsole ausführe, wird mir alles aufgelistet:
Wenn ich das in C# anwenden möchte, erhalte ich nichts von dem Standard-Ausgabekanal zurück, wie es scheint.
So ist der aktuelle Stand:
- Process p = new Process();
- p.StartInfo.UseShellExecute = false;
- p.StartInfo.RedirectStandardOutput = true;
- p.StartInfo.FileName = "cmd.exe";
- p.StartInfo.Arguments = "/c query user /server:ts-01";
- p.Start();
- string output = p.StandardOutput.ReadToEnd();
- p.WaitForExit();
Hier auch noch ein Versuch mit einem BackgroundWorker:
- List<string> sessions = new List<string>();
- BackgroundWorker bw = new BackgroundWorker();
- bw.DoWork += (sender, args) =>
- {
- Process p = Process.Start(
- new ProcessStartInfo("cmd.exe")
- {
- Arguments = "/c query user /server:ts-01"
- , RedirectStandardOutput = true
- , UseShellExecute = false
- }
- );
- if (p != null)
- {
- p.OutputDataReceived += (s, e) => sessions.Add(e.Data);
- p.BeginOutputReadLine();
- }
- };
- bw.RunWorkerAsync();
Alles anzeigen
Egal, wie ich es umsetze, das Resultat bleibt leer.
Wenn ich eine Batch-Datei erstelle und diese standalone ausführe, funktioniert es ebenfalls:
- cmd.exe /c query user /server:ts-01
Ich erkenne gerade nicht, was beim C# falsch ist?!
Berechtigungen sind natürlich entsprechende vorhanden. Weiß jemand mehr?