Veröffentlicht 22. Juni 20214 j Hallöchen, ich würde gerne über das C#-Prgramm den Befehl query session ausführen. Der Befehl wird aber dann in der Konsole nicht erkannt. Starte ich die Eingabeauffprderung direkt aus Windows und gebe den Befehl manuell ein, wird dieser problemlos ausgeführt. Auch eine Batch-Datei mit diesem Inhalt wird nicht über das c#-Programm ausgeführt, manuell jedoch schon. public void btn7_Click(object sender, RoutedEventArgs e) { Process p = new Process(); ProcessStartInfo startInfo = new ProcessStartInfo(); startInfo.FileName = "cmd.exe" startInfo.Verb = "runas"; //startInfo.Arguments = @"/k " + "query session"; p.StartInfo = startInfo; p.Start(); } Viele Grüße und danke im voraus
22. Juni 20214 j Ich habe mal die Antwort des Stackoverflow Artikels getestet: Process p = new Process(); p.StartInfo.FileName = "cmd.exe"; p.StartInfo.Arguments = "/c dir *.cs"; p.StartInfo.UseShellExecute = false; p.StartInfo.RedirectStandardOutput = true; p.Start(); string output = p.StandardOutput.ReadToEnd(); p.WaitForExit(); Console.WriteLine("Output:"); Console.WriteLine(output); Das scheint zu funktionieren.
Erstelle ein Konto oder melde dich an, um einen Kommentar zu schreiben.