I have written the c# console application. when i lauch the application (not using cmd). i can see it is listed in process list in task manager ,now i need to write another application in which i need to find whether previous application is running or not ,i know the application name and path so i have written management object searcher query to get the list of process and also i am using the path to compare it with its executable path ,code is given below
var name="test.exe"
var path="D:\test"
var processCollection = new ManagementObjectSearcher("SELECT * " + "FROM Win32_Process " + "WHERE Name='" + name + "'").Get();
if (processCollection.Count > 0)
{
foreach(var process in processCollection)
{
var executablePath=process["ExecutablePath"];
if(executablePath.equals(path))
{
return true;
}
}
}
but executable path is always null.
how to get its executable path?.
I can not only use process name because i am using common name like startserver and stopserver to my application. so i need to ensure it executable path.