Hi,
I have created an application to check if our application process is running. Because there is more than one instance of this process running (6 processes) with the same name, the only way to identify which is down is to look at the start up parameter in the CommanLine from SELECT CommandLine FROM Win32_Process. The fist start up parameter is the directory which is used to uniquely identify which one is down.
So what I am trying to do is to loop using foreach and in my app.config have list where i can identify from the list which process is not running. But it does exactly what foreach does. All i want is to see which String of the site is not in the loop.
<add key="sites" value="D:\site,D:\site1,D:\site2"/>
Your help will be much appreciated.
:welcoming:
I have created an application to check if our application process is running. Because there is more than one instance of this process running (6 processes) with the same name, the only way to identify which is down is to look at the start up parameter in the CommanLine from SELECT CommandLine FROM Win32_Process. The fist start up parameter is the directory which is used to uniquely identify which one is down.
So what I am trying to do is to loop using foreach and in my app.config have list where i can identify from the list which process is not running. But it does exactly what foreach does. All i want is to see which String of the site is not in the loop.
<add key="sites" value="D:\site,D:\site1,D:\site2"/>
string wmiQuery = string.Format("SELECT CommandLine FROM Win32_Process WHERE Name LIKE '{0}%{1}'", proc, ".exe"); ManagementObjectSearcher searcher = new ManagementObjectSearcher(wmiQuery); ManagementObjectCollection retObjectCollection = searcher.Get(); Console.WriteLine(retObjectCollection.Count); if (retObjectCollection.Count < 6) { foreach (ManagementBaseObject retObject in retObjectCollection) { string cmdLine = retObject["CommandLine"].ToString(); string leftStr = cmdLine.Substring(0, 30); string shortLeftStr = leftStr.Substring(0, 14); Console.WriteLine(shortLeftStr ); foreach(string site in sites) { if (site.startswith(shortLeftStr)) { console.writeline(site + " is up and running"); } else { console.writeline(site + " is Down"); } } } }
Your help will be much appreciated.
:welcoming:
Last edited by a moderator: