-
April 3rd, 2010, 07:38 PM
#1
Checking if process exists
I'm trying to find a method that will return true if a process exists, and false if it does not. I came across this one, but can't seem to get it to work properly.
Code:
using System.Diagnostics;
int main() {
if IsProcessOpen(firefox) == true {
MessageBox(NULL, "Firefox is running", NULL, NULL);
}
}
public bool IsProcessOpen(string name)
{
foreach (Process clsProcess in Process.GetProcesses()) {
if (clsProcess.ProcessName.Contains(name))
{
return true;
}
}
return false;
}
}
How can I change this so it works correctly o.o?
any help would be appriciated,
thanks,
Coukapecker
-
April 3rd, 2010, 08:03 PM
#2
Re: Checking if process exists
That's managed code / c#. So of course it wont compile as c++ code
I suggest you look at win api / msdn documents for process enumeration.
here: http://msdn.microsoft.com/en-us/libr...89(VS.85).aspx is probably a good start.
-
April 4th, 2010, 03:23 PM
#3
Re: Checking if process exists
You can use;
WaitForSingleObject( pi.hProcess, INFINITE );
CloseHandle( pi.hProcess );
CloseHandle( pi.hThread );
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|