求C#如何知道一个程序是否运行并获取其程序路径,网上各种方法都试了,不行

求C#如何知道一个程序是否运行并获取其程序路径,网上各种方法都试了,不行

string sPath = getPath(@"firefox"); 

private string getPath(string sProName, string lpWindowName = null)
{
    string strPath="";
    Process[] pro;
    try
    {
        pro = Process.GetProcessesByName(sProName); //通过进程名找
        if (pro.Length == 0)
        {
            return "";
        }
        else
        {
            strPath = pro[0].MainModule.FileName; 
        }

    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message, "", MessageBoxButtons.OK);
    }

    return strPath;
}