【问题标题】:CreateProcess call returns error code 50CreateProcess 调用返回错误代码 50
【发布时间】:2012-09-03 20:01:01
【问题描述】:

尝试使用 Createprocess 在给定路径中启动 Windows Explorer,但我不断收到

系统错误。代码 50。不支持该请求。

我做错了什么?

procedure TfrmProjectManager.OpenFolderinExplorer(const aPath: string);
  function GetWinDir: String;
  var
    Buffer: array[0..MAX_PATH] of Char;
  begin
    GetWindowsDirectory(Buffer, SizeOf(Buffer));
    SetString(Result, Buffer, StrLen(Buffer));
  end;

var
  strCmdLine    : String;
  fStartInfo    : TStartupInfo;
  fProcessInfo  : TProcessInformation;

begin

  try
    if sysutils.DirectoryExists(aPath) or 
       (MessageDlg('Folder [%s] not found. Create it?', mtConfirmation, mbYesNo, 0)=mrYes) then
    begin
      sysutils.ForceDirectories(aPath);
      FillChar(fStartInfo,sizeof(fStartInfo),0);
      FillChar(fPRocessInfo, Sizeof(fProcessInfo),0);

      fStartInfo.cb:=sizeof(fStartInfo);
      fStartInfo.lpReserved := nil;
      fStartInfo.lpDesktop := nil;
      fStartInfo.lpTitle := nil;
      fStartInfo.dwFlags := STARTF_USESHOWWINDOW ;
      fStartInfo.wShowWindow := SW_SHOW;
      fStartInfo.cbReserved2 := 0;
      fStartInfo.lpReserved2 := nil;

      strCmdLine := '"' + GetWinDir + '\explorer.exe"';

    if not CreateProcess(nil,PChar(strCmdLine),nil,nil,False, 0,nil,PChar(aPath),fStartInfo,fProcessInfo) then
     RaiseLastOSError;

  end

  except
    on E:TObject do
      if not IsAbortException(E) then
        raise;
  end;
end;

我在 CreateProcess 中尝试了各种参数组合,但似乎无法找到正确的组合。

【问题讨论】:

  • 试试Windows资源管理器命令行,奇怪的格式如下:explorer.exe /e,目录,例如explorer.exe /e,C:\Projects\Project1

标签: delphi delphi-xe2


【解决方案1】:

我想说你不应该在这里使用CreateProcess。而不是调试您的CreateProcess,我将为您提供我认为是打开文件夹视图的正确方法。致电ShellExecute

ShellExecute(0, '', PChar(aPath), '', '', SW_SHOWNORMAL);

这样您就可以让 shell 决定向用户显示文件夹内容的适当方式。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多