I have a simple application that gets windows services running on my machine, filter the results by their name and displays service name, port and status of the service.
Right now, I successfully find name and status, but I'm having a hard time finding a way to find a property related to the Port. Do i have access to this info by the method below, or would I need to change my approach entirely?
ManagementObjectSearcher searcher =
new ManagementObjectSearcher("SELECT * FROM Win32_Service");
ManagementObjectCollection collection = searcher.Get();
foreach (ManagementObject obj in collection)
{
string name = obj["Name"] as string;
if (name.StartsWith("something"))
{
string pathName = obj["PathName"] as string;
string status = obj["State"] as string;
//string port = ??;
MyService sc = new MyService()
{
Name = name,
Status = status,
//Port = port,
Updated = true
};
}
}
Thanks!