Autor Beitrag
Lihlu
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 53



BeitragVerfasst: Mo 22.01.18 13:46 
Hallo zusammen,

ich sitze derzeit an einem Tool was mir Remote Programme von anderen Rechnern ausliest. Soweit auch alles okey:

ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
Process p = new Process();
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.FileName = @"C:\Windows\System32\wbem\wmic.exe";
p.StartInfo.Arguments = "/node:" + HostnameBox.Text + " product get name";
p.StartInfo.CreateNoWindow = true;
p.Start();
          
string output = p.StandardOutput.ReadToEnd();

p.WaitForExit();
           
richTextBox1.Text = output;

Soweit liest er mir auch alles in die RichTextBox aus.

Nun möchte ich den "output" allerdings säuberlich pro Programmname in eine Listbox haben. Wie genau stelle ich das an ? Die Programme haben ja auch öfters mal ein Leerzeichen im Namen.

Der Output sieht in der RichTextBox so aus:

ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
Name                                                                                                            NetSpeedMonitor 2.5.4.0
 x64                                                                                     Microsoft Visual Studio 2015 Tools for Unity                                                                    
Kuando Busylight and KuandoBox for Lync and Skype                                                               MySQL Server 5.5                                                                                                
Kuando Busylight and KuandoBox for Skype for Business                                                           CLC Termin synchronizer                                                                                         
Auslesetool ABC Datalog                                                                                           erLT                                                                                                            
Microsoft Application Error Reporting                                                                           Office 15 Click-to-Run 
Extensibility Component                                                                  Office 15 Click-to-Run Localization Component

usw.

Wisst ihr wie ich dies umsetzen kann ?

Vielen Dank

Moderiert von user profile iconTh69: Beitragsformatierung überarbeitet.
Th69
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Moderator
Beiträge: 4764
Erhaltene Danke: 1052

Win10
C#, C++ (VS 2017/19/22)
BeitragVerfasst: Mo 22.01.18 13:59 
Wenn ich bei mir "wmic product get name" lokal ausführe, dann werden mir die installierten Programme jeweils mit einem Zeilenumbruch angezeigt.
Bei der RichTextBox werden jedoch nur "\r\n" als Zeilenumbruch erkannt, nicht ein einfaches '\n'.

Wenn du in einer Schleife zeilenweise per p.StandardOutput.ReadLine() (s. StreamReader.ReadLine) die Ausgabe einliest, dann kannst du die einzelnen Zeilen in eine List<string> packen und per DataBinding (DataSource) der ListBox übergeben.

Für diesen Beitrag haben gedankt: Lihlu
Lihlu Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 53



BeitragVerfasst: Mo 22.01.18 14:05 
Ich denke ich habe verstanden was du meinst. Ich werde nun mal ein wenig ausprobieren und hoffe das ich als leihe das auf die reihe bekomme - Danke dir schon mal
Th69
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Moderator
Beiträge: 4764
Erhaltene Danke: 1052

Win10
C#, C++ (VS 2017/19/22)
BeitragVerfasst: Mo 22.01.18 14:08 
leihe -> Laie :D

Für diesen Beitrag haben gedankt: Lihlu
Lihlu Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 53



BeitragVerfasst: Mo 22.01.18 14:17 
So simple! Danke dir :P


ausblenden C#-Quelltext
1:
2:
            foreach (var ProgramOutput in output.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries))
                Programlistbox.Items.Add(ProgramOutput);
Th69
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Moderator
Beiträge: 4764
Erhaltene Danke: 1052

Win10
C#, C++ (VS 2017/19/22)
BeitragVerfasst: Mo 22.01.18 14:36 
Gerade das meinte ich eben nicht...
Warum erst die ganze Ausgabe einlesen und dann wieder zerstückeln?
Und DataBinding setzt du auch nicht ein, s. ListBox Tutorial.
Lihlu Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 53



BeitragVerfasst: Mo 22.01.18 17:05 
Funktioniert allerdings so ohne Probleme. Zum glück führen beim Programmieren immer mehrere Wege nach Rom. Das ist es, was ich als Systemintegratorin so daran mag. Vllt. gehe ich irgendwann noch mal den Weg und lerne Anwendungsentwicklung und nicht nur den 1 Jahr Grundkurs ^^ :)

Trotzdem noch mal danke
Einloggen, um Attachments anzusehen!
Frühlingsrolle
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Mo 22.01.18 17:36 
- Nachträglich durch die Entwickler-Ecke gelöscht -
Ralf Jansen
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 4700
Erhaltene Danke: 991


VS2010 Pro, VS2012 Pro, VS2013 Pro, VS2015 Pro, Delphi 7 Pro
BeitragVerfasst: Mo 22.01.18 18:40 
Wo gerade das Stichwort "Warum" gefallen ist. Warum die WMI Konsolenanwendung benutzen um an WMI Daten zu kommen um sich dann beim Zerlegung des Konsolenoutputs schwer zu tun wenn ich WMI auch direkt abfragen kann?
Symbroson
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 382
Erhaltene Danke: 67

Raspbian, Ubuntu, Win10
C, C++, Python, JavaScript, Lazarus, Delphi7, Casio Basic
BeitragVerfasst: Mo 22.01.18 21:45 
Weil es sonst zu einfach wäre

_________________
most good programmers do programming not because they expect to get paid or get adulation by the public, but because it's fun to program. (Linus Torvalds)
Frühlingsrolle
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Di 23.01.18 07:27 
- Nachträglich durch die Entwickler-Ecke gelöscht -