Check whether specified application is running

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Dear all,
how can I check whether a specified application is running. I tried the
following code below...but still not able to detect

private static readonly int ERROR_ALREADY_EXIST = 183;

[DllImport("coredll.dll", SetLastError=true)]
public static extern int CreateProcess(
string strImageName, string strCmdLine, IntPtr pProcessAttributes,
IntPtr pThreadAttributes , int bInheritsHandle, int dwCreationFlags,
IntPtr pEnvironment,
IntPtr pCurrentDir, Byte[] bArray, ProcessInfo oProc);

[DllImport("coredll.dll", EntryPoint="GetLastError")]
private static extern int GetLastError();

[DllImport("coredll.dll", EntryPoint="CreateMutexW")]
public static extern int CreateMutex(
IntPtr lpMutexAttributes, bool bInitialOwner, string MutexName);

if (CreateMutex(IntPtr.Zero, true, "iexplore.exe") != 0)
{
int lstErr = GetLastError();
if (lstErr == ERROR_ALREADY_EXIST)
{
return true;
}
}
return false;


I tried to put iexplore.exe or Internet Explorer, still return false
any suggestion?
 
Unless you are the one who *started* the other application. In that case,
you can use WaitForSingleObject() to check whether the process handle of the
other application is signaled (done running), or not signaled (still
running).

Paul T.

Alex Feinman said:
The approach you are using works only with your own application. If you
want to check for *any* app to be running, you will need to enumerate
processes as described here:
http://msdn.microsoft.com/library/d.../dnnetcomp/html/ProcessManager.asp?frame=true

--
Alex Feinman
---
Visit http://www.opennetcf.org
Bryan Gan said:
Dear all,
how can I check whether a specified application is running. I tried the
following code below...but still not able to detect

private static readonly int ERROR_ALREADY_EXIST = 183;

[DllImport("coredll.dll", SetLastError=true)]
public static extern int CreateProcess(
string strImageName, string strCmdLine, IntPtr pProcessAttributes,
IntPtr pThreadAttributes , int bInheritsHandle, int dwCreationFlags,
IntPtr pEnvironment,
IntPtr pCurrentDir, Byte[] bArray, ProcessInfo oProc);

[DllImport("coredll.dll", EntryPoint="GetLastError")]
private static extern int GetLastError();

[DllImport("coredll.dll", EntryPoint="CreateMutexW")]
public static extern int CreateMutex(
IntPtr lpMutexAttributes, bool bInitialOwner, string MutexName);

if (CreateMutex(IntPtr.Zero, true, "iexplore.exe") != 0)
{
int lstErr = GetLastError();
if (lstErr == ERROR_ALREADY_EXIST)
{
return true;
}
}
return false;


I tried to put iexplore.exe or Internet Explorer, still return false
any suggestion?
 
Back
Top