如:
  txt文件 得到 D:\winnt\notepad.exe
  dsw文件 得到 D:\Program Files\Microsoft Visual Studio\Common\MSDev98\Bin\MSDEV.EXEShellExecute就做到了~~  请问有什么简单方法可以实现吗?

解决方案 »

  1.   

    FindExecutable or AssocQueryString
      

  2.   

    char pszExeName[MAX_PATH];
    CFile tempFile;
    tempFile.Open("c:\\temp.txt",CFile::modeCreate );
    tempFile.Close();
    FindExecutable("c:\\temp.txt",NULL,pszExeName);
    CFile::Remove("c:\\temp.txt");
    AfxMessageBox(pszExeName);
      

  3.   

    agree _foo(void) !HINSTANCE FindExecutable(
        LPCTSTR lpFile,
        LPCTSTR lpDirectory,
        LPTSTR lpResult
    );HRESULT AssocQueryString(
        ASSOCF flags, 
        ASSOCSTR str, 
        LPCTSTR pszAssoc, 
        LPCTSTR pszExtra, 
        LPTSTR pszOut, 
        DWORD *pcchOut
    );
      

  4.   

    FindExecutable!! 好的!!!谢谢大家!!
      

  5.   

    使用FindExecutable这个函数找到exe文件后用CreateProcess打开,发现WaitForSingleObject不能够阻塞了,为什么? 
      

  6.   

    HANDLE process=OpenProcess(PROCESS_QUERY_INFORMATION|SYNCHRONIZE,FALSE,pid);
    if (!process) cot<<”Slave:Error opening process\n”;
    cout<<”Slave :Waiting for master to finish\n”;
    cout.flush();
    if (WaitForSingleObject(process,INFINITE)==STAUTE_WAIT_0)
      cout<<”Slave:Master completed\n”;
    else
      cout<<”Slave:Unexpected error\n”;
    exit(0);
    }