title: How to check if a process is running or not using C++
body: <p>I should not display  certain context menu options if one process is not running?.
  I am checking if the process is running or not using the process name.</p>
  
  <p>But the issue is, the process name is showing different way in different windows platforms.</p>
  
  <p>ie, windows 64 bit process name on windows task bar is " <strong>applicationname.exe</strong>"</p>
  
  <p>some windows xp machine shows the same process name as "<strong>applica~2.exe</strong>"</p>
  
  <p>Please let me know the  consistent way to check if the process is running or not?  </p>
  
  <p>My development environment is C++ and Visual Studio 2010</p>
  
  <pre><code>   DWORD getProcessID(const std::wstring&amp; processName)
     {
         PROCESSENTRY32 info;
         info.dwSize = sizeof(info);
  
         HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL);
         if ( snapshot == INVALID_HANDLE_VALUE )
               return 0;
  
         Process32First(snapshot, &amp;info);
         if ( !processName.compare(info.szExeFile) )
         {
               CloseHandle(snapshot);
               return info.th32ProcessID;
         }
  
         while ( Process32Next(snapshot, &amp;info) )
         {
                if ( !processName.compare(info.szExeFile) )
                 {
                      CloseHandle(snapshot);
                      return info.th32ProcessID;
                 }
         }
  
        CloseHandle(snapshot);
       return 0;
     }
  </code></pre>