If you have the process name, just call WaitForSingleObject with timeout zero and check the result. If you get a timeout return code, it's still running.
Your code works for me with "notepad.exe" for pName, but I've only tried it on my old, security lax Windows XP machine.
Is it the OpenProcess call that's failing? You could try checking the value of hProcess and handling the error.
Or the EnumProcesses call?
Andy
PS Once you have the handle to the process you're interested in, you can call GetExitCodeProcess. It will returns STILL_ACTIVE if the process is still running.