ShellExecute可以根据文件后缀调用关联程序执行文件.
我现在的问题是我必须把某个exe文件的后缀改成dat,然后使用ShellExecute来执行这个程序,但是它直接把这个可执行文件当作媒体文件来执行了.
ShellExecute(Handle, nil, PChar('.\Client.dat'), nil, nil, SW_SHOW);
就像上面这样Client.dat实际上是个可执行文件,我怎么才能在不修改后缀的前提下叫ShellExecute把这个Client.dat当然可执行来执行呢?

解决方案 »

  1.   

    有想法!!先赞一个用ShellExecute如何来做,还真不清楚,从他名字上的shell这个字眼来看,估计很难有办法。当然,改名字是一个办法,再不改名字的前提下,可以考虑用CreateProcess来做下列代码中的'd:\Project1.dat'就是一个可执行文件,改了后缀名。procedure TForm1.Button1Click(Sender: TObject);
    var  ProcessInfo: TProcessInformation;
      StartUpInfo: TStartupInfo;
    begin  FillChar(StartUpInfo, SizeOf(StartUpInfo), $00);
      StartUpInfo.dwFlags := STARTF_USESHOWWINDOW;
      StartUpInfo.wShowWindow := SW_SHOW;
      if CreateProcess(nil, PChar('d:\Project1.dat'), nil, nil,
        False, IDLE_PRIORITY_CLASS, nil, nil, StartUpInfo,
        ProcessInfo) then
      begin
        CloseHandle(ProcessInfo.hThread);
        CloseHandle(ProcessInfo.hProcess);
      end;
    end;
      

  2.   

    // 用WinExec也成
    WinExec('.\Project1.dat', SW_SHOW);