What is this?

This knowledgebase contains questions and answers about PRTG Network Monitor and network monitoring in general.

Learn more

PRTG Network Monitor

Intuitive to Use. Easy to manage.
More than 500,000 users rely on Paessler PRTG every day. Find out how you can reduce cost, increase QoS and ease planning, as well.

Free Download

Top Tags


View all Tags

C# Get Application name "Last Message: No "result" or "error" in XML response."

Votes:

0

Hi, I use code shown below to get application name, but it shows "No "result" or "error" in XML response."

Process[] processlist = Process.GetProcesses();
       Console.WriteLine(@"<?xml version=""1.0"" encoding=""UTF-8"" ?>");
       Console.WriteLine(@"<prtg>");
       foreach (Process process in processlist)
       {
           if (!String.IsNullOrEmpty(process.MainWindowTitle))
           {
               Console.WriteLine("   " + @"<result>");
               Console.WriteLine("     " + @"<channel>" + process.MainWindowTitle + "</channel>");
               Console.WriteLine("     " + @"<unit>" + "Custom" + "</unit>");
               Console.WriteLine("     " + @"<value>" + "0" + "</value>");
               Console.WriteLine("   " + @"</result>");
           }
       }
       Console.WriteLine("  </prtg>");
    
and i found a phenomenon, when i remove the for loop then hard code shown below, it Works!!!

Process[] processlist = Process.GetProcesses();
       Console.WriteLine(@"<?xml version=""1.0"" encoding=""UTF-8"" ?>");
       Console.WriteLine(@"<prtg>");
               Console.WriteLine("   " + @"<result>");
               Console.WriteLine("     " + @"<channel>" + "process.MainWindowTitle" + "</channel>");
               Console.WriteLine("     " + @"<unit>" + "Custom" + "</unit>");
               Console.WriteLine("     " + @"<value>" + "0" + "</value>");
               Console.WriteLine("   " + @"</result>");
               Console.WriteLine("   " + @"<result>");
               Console.WriteLine("     " + @"<channel>" + "process.MainWindowTitle" + "</channel>");
               Console.WriteLine("     " + @"<unit>" + "Custom" + "</unit>");
               Console.WriteLine("     " + @"<value>" + "0" + "</value>");
               Console.WriteLine("   " + @"</result>");

       Console.WriteLine("  </prtg>");

Could u help me to solve the problem ? Thanks.

c# prtg wmi

Created on Feb 14, 2017 8:10:01 AM

Last change on Feb 14, 2017 8:26:14 AM by  Torsten Lindner [Paessler Support]



10 Replies

Votes:

0

Could you post the actual the actual output when using the for loop? Additionally, check out String.Format, it allows you to replace placeholders in strings which will actually make your code much more readable :)

Created on Feb 14, 2017 10:14:59 AM by  Stephan Linke [Paessler Support]



Votes:

0

Hi, this is the output, please check it. Thanks. : D

<?xml version="1.0" encoding="UTF-8" ?>
<prtg>
   <result>
     <channel>Internet Information Services (IIS) 管理員</channel>
     <unit>Custom</unit>
     <value>0</value>
   </result>
   <result>
     <channel>file:///c:/users/administrator/documents/visual studio 2012/Projects/ConsoleApplication2/ConsoleApplication2/bin/Debug/ConsoleApplication2.EXE</channel>
     <unit>Custom</unit>
     <value>0</value>
   </result>
   <result>
     <channel>ConsoleApplication2 [執行] - Microsoft Visual Studio (系統管理員)</channel>
     <unit>Custom</unit>
     <value>0</value>
   </result>
  </prtg>

Created on Feb 15, 2017 12:31:08 AM

Last change on Feb 15, 2017 7:22:39 AM by  Luciano Lingnau [Paessler]



Votes:

0

The output actually works in PRTG...anything else after the output in the console? Does the application need special permissions?

Created on Feb 15, 2017 7:33:25 AM by  Stephan Linke [Paessler Support]



Votes:

0

Hi, there is nothing else after the output in the console, no special permission. Here is the whole code. Thanks.

using System;
using System.Diagnostics;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;


class ConsoleApplication2
{
   public static void Main()
   {
       Process[] processlist = Process.GetProcesses();
       Console.WriteLine(@"<?xml version=""1.0"" encoding=""UTF-8"" ?>");
       Console.WriteLine(@"<prtg>");
       foreach (Process process in processlist)
       {
           if (!String.IsNullOrEmpty(process.MainWindowTitle))
           {
               Console.WriteLine("   " + @"<result>");
               Console.WriteLine("     " + @"<channel>" + process.MainWindowTitle + "</channel>");
               Console.WriteLine("     " + @"<unit>" + "Custom" + "</unit>");
               Console.WriteLine("     " + @"<value>" + "0" + "</value>");
               Console.WriteLine("   " + @"</result>");
           }
       }
       Console.WriteLine("  </prtg>");
      
   }
}

Created on Feb 15, 2017 7:41:56 AM

Last change on Feb 15, 2017 8:20:20 AM by  Stephan Linke [Paessler Support]



Votes:

0

What values are you actually trying to read out with that sensor? Just asking, because the Windows Process sensor might be what you're looking for. Other than that, the code looks fine... Did you try to change the sensor settings so it's execute within a different user context (Security Settings in the settings tab)?

Created on Feb 15, 2017 8:22:31 AM by  Stephan Linke [Paessler Support]



Votes:

0

I want to read the "application name" in task manager tab, just want to know what is running in server.

Created on Feb 15, 2017 8:32:41 AM



Votes:

0

I found the application name is always null ! but i run it on local, it is ok did you solve it ?

Created on Sep 5, 2017 9:28:01 AM



Votes:

0

As mentioned, did you try to change the sensor settings so it's executed within a different user context (Security Settings in the settings tab of the sensor)?


Kind regards, Stephan Linke

Created on Sep 5, 2017 10:23:08 AM by  Stephan Linke [Paessler Support]



Votes:

0

Yes, but it still not work. could u show me the example to list the desktop application name?

Created on Sep 6, 2017 5:24:55 AM



Votes:

0

Are you actually using the user that has the applications opened? This may possibly not work at all due to the different sessions used by Windows in the background.


Kind regards,
Stephan Linke, Tech Support Team

Created on Sep 6, 2017 8:35:24 AM by  Stephan Linke [Paessler Support]




Disclaimer: The information in the Paessler Knowledge Base comes without warranty of any kind. Use at your own risk. Before applying any instructions please exercise proper system administrator housekeeping. You must make sure that a proper backup of all your data is available.