By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,723 Members | 1,095 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,723 IT Pros & Developers. It's quick & easy.

Find if service is running using System.Management

P: n/a
I am trying to determine if a particular process is running. I think I am
probably missing something obvious, but here is what I have so far...

ManagementObjectSearcher msProcessCcmExec = new
ManagementObjectSearcher("SELECT * FROM Win32_Process WHERE Name =
'CcmExec.exe'");

foreach (ManagementObject mo in msProcessCcmExec.Get())
{
logWrite.WriteLine(mo["Name"].ToString() + " is
running.");
}

This works fine if ccmexec.exe is running as it will write the line to my
log file. But what I really want to do is find out if ccmexec.exe is
running. So, how would that best be accomplished? I need to answer the
questions, "Is ccmexec.exe running?".
Thanks in advance for any help.

Jul 9 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Primera,

If the program wasn't running, then it wouldn't be returned to you in
the query. It's only going to be returned to you if the process is actually
executing.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Primera" <Pr*****@discussions.microsoft.comwrote in message
news:0A**********************************@microsof t.com...
>I am trying to determine if a particular process is running. I think I am
probably missing something obvious, but here is what I have so far...

ManagementObjectSearcher msProcessCcmExec = new
ManagementObjectSearcher("SELECT * FROM Win32_Process WHERE Name =
'CcmExec.exe'");

foreach (ManagementObject mo in msProcessCcmExec.Get())
{
logWrite.WriteLine(mo["Name"].ToString() + " is
running.");
}

This works fine if ccmexec.exe is running as it will write the line to my
log file. But what I really want to do is find out if ccmexec.exe is
running. So, how would that best be accomplished? I need to answer the
questions, "Is ccmexec.exe running?".
Thanks in advance for any help.

Jul 9 '06 #2

P: n/a
Yes, that makes sense. Either way though I am left with an object of type
ManagementObjectSearcher or if I use a foreach an object of type
ManagementObject. So then I seem to be running into a problem testing if
these object are empty so that I can answer the question of whether the
process is running. I hope this makes sense. What type of statement can I
use to discern if the ManagementObjectSearcher is empty? I have tried using:

if (msProcessCcmExec != null)

but this returns an error about casting to bool, and I cannot manually cast
it to bool either. I appreciate your help.

"Nicholas Paldino [.NET/C# MVP]" wrote:
Primera,

If the program wasn't running, then it wouldn't be returned to you in
the query. It's only going to be returned to you if the process is actually
executing.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Primera" <Pr*****@discussions.microsoft.comwrote in message
news:0A**********************************@microsof t.com...
I am trying to determine if a particular process is running. I think I am
probably missing something obvious, but here is what I have so far...

ManagementObjectSearcher msProcessCcmExec = new
ManagementObjectSearcher("SELECT * FROM Win32_Process WHERE Name =
'CcmExec.exe'");

foreach (ManagementObject mo in msProcessCcmExec.Get())
{
logWrite.WriteLine(mo["Name"].ToString() + " is
running.");
}

This works fine if ccmexec.exe is running as it will write the line to my
log file. But what I really want to do is find out if ccmexec.exe is
running. So, how would that best be accomplished? I need to answer the
questions, "Is ccmexec.exe running?".
Thanks in advance for any help.


Jul 9 '06 #3

P: n/a
I think I have solved this using:

ManagementObjectSearcher msProcessCcmSetup = new ManagementObjectSearcher("SELECT
* FROM Win32_Process WHERE Name = 'CcmSetup.exe'");
ManagementObjectCollection moCcmSetup = msProcessCcmSetup.Get();
if (moCcmSetup.Count == 0)
{
logWrite.WriteLine(moCcmSetup.Count);
logWrite.WriteLine("CcmSetup.exe is not running.");
}
if (moCcmSetup.Count != 0)
{
foreach (ManagementObject mo in moCcmSetup)
{
logWrite.WriteLine(mo["Name"] + " is running.");
}
}
I am trying to determine if a particular process is running. I think
I am probably missing something obvious, but here is what I have so
far...

ManagementObjectSearcher msProcessCcmExec = new
ManagementObjectSearcher("SELECT * FROM Win32_Process WHERE Name =
'CcmExec.exe'");

foreach (ManagementObject mo in
msProcessCcmExec.Get())
{
logWrite.WriteLine(mo["Name"].ToString() + " is
running.");
}
This works fine if ccmexec.exe is running as it will write the line to
my
log file. But what I really want to do is find out if ccmexec.exe is
running. So, how would that best be accomplished? I need to answer
the
questions, "Is ccmexec.exe running?".
Thanks in advance for any help.

Jul 9 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.