【问题标题】:Delphi RAD Studio 10.2, unable to browse windows system folder using FileOpenDialogDelphi RAD Studio 10.2,无法使用 FileOpenDialog 浏览 windows 系统文件夹
【发布时间】:2020-05-05 19:35:27
【问题描述】:

我需要能够在运行 Windows DNS 服务器的 Windows server 2016 实例上枚举C:\Windows\system32\dns 下存在的文件夹。

尝试了FindFirst()/FindNext() 并没有得到任何结果,我构建了一个快速的 VCL 表单应用程序来了解发生了什么。我有一个TButton 和一个TEdit,按钮的OnClick 如下:

procedure TForm1.Button1Click(Sender: TObject);
begin
  FDir := 'C:\Windows\System32\';

  with TFileOpenDialog.Create(nil) do
    try
      Title := 'Select Directory';
      Options := [fdoPickFolders, fdoPathMustExist, fdoForceFileSystem];
      OkButtonLabel := 'Select';
      DefaultFolder := FDir;
      FileName := FDir;
      if Execute then
        Edit1.Text := Filename;
    finally
      Free;
    end;
end;

当我以管理员身份或通常在服务器上运行此程序并尝试浏览到 FileOpenDialog 中的文件夹 C:\Windows\system32\dns\ 时,我收到一个错误:

Windows 找不到“C:\Windows\system32\dns”。检查拼写并重试。

但是,我知道该文件夹存在,我可以使用服务器上的 Windows 资源管理器浏览它,因此肯定是 Delphi 代码存在问题,或者应用程序运行的权限存在问题。

请问,谁能建议我需要做些什么来解决这个问题?

【问题讨论】:

  • 删除fdoForceFileSystem是否有同样的问题?
  • 构建 64 位程序。或者阅读文件系统重定向器。
  • @RemyLebeau 是的,删除 fdoForceFileSystem 后它的行为仍然相同。

标签: delphi


【解决方案1】:

感谢@SertacAkyuz 提醒我有关文件系统重定向 - 尝试从 32 位程序访问 %Windir%\system32 将被重定向到不包含 dns 文件夹的 %Windir%\SysWow64。

您可以使用虚拟别名 %Windir%\Sysnative 从 32 位应用程序访问实际的 system32 文件夹,这适用于上述情况。所以浏览到 %Windir%\sysnative\dns 可以让我正确枚举文件夹。

【讨论】:

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