Reputation: 53
I need to be able to enumerate the folders present under C:\Windows\system32\dns
on a Windows server 2016 instance running Windows DNS server.
Having tried FindFirst()
/FindNext()
and getting no results, I built a quick VCL Forms App to understand what was happening. I have a TButton
and a TEdit
, and the button's OnClick
is below:
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;
When I run this - either as Administrator, or normally, on the server - and try to browse to the folder C:\Windows\system32\dns\
in the FileOpenDialog
, I get an error:
Windows can't find 'C:\Windows\system32\dns'. Check the spelling and try again.
However, I know the folder exists, and I can browse it using Windows Explorer on the server, so there must be an issue with the Delphi code, or the permissions the App is running under.
Please, can anyone suggest what I need to do to fix this?
Upvotes: 0
Views: 221
Reputation: 53
Thanks to @SertacAkyuz for reminding me about file system redirection - trying to access %Windir%\system32 from a 32bit program will be redirected to %Windir%\SysWow64 which doesn't contain the dns folder.
You can use the virtual alias %Windir%\Sysnative to gain access to the actual system32 folder from a 32bit application, and that works for the above case. so browsing to %Windir%\sysnative\dns allows me to enumerate the folders correctly.
Upvotes: 4