尝试使用 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 中尝试了各种参数组合,但似乎无法找到正确的组合。