问题
I am developing a C# program that is run from a server and monitors processes on another set of servers. The processes I am monitoring all have the same exe name, but different windows title names. I am looking for a way to pull the windows title names from these processes remotely.
Basically what i would like to do is the following;
Process[] processList = Process.GetProcesses("ServerName");
foreach (Process p in processList)
{
try
{
Console.WriteLine(p.MainWindowTitle);
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
}
However this is not supported by .NET
Does anyone know of another way?
回答1:
I won't tell you this is the best approach, but it's possible to use it. You could create a simple service (windows service) and install it on each server. You might want to implement auto update functionality and therefore after installation you don't have to reinstall this service app on every machine. And this service app gets processes and associated windows titles (it may be more than one window within single process) and returns it to the machine that queries that information. I think you could use WCF here. And other advantage is that you can add more other functionality more easier.
来源:https://stackoverflow.com/questions/11352618/c-sharp-get-main-window-title-of-processes-on-a-remote-machine