List of files lazarus / 34-Windows ---------------------------------------------------------------------- Serg7 · 2022-11-01 05:51 Searching for files works fine, but if scan the c:\windows\system32\config\ directory, then with administrator rights it only shows folders: Journal\ RegBack\ systemprofile\ TxR\ At the same time Total Commander shows: bbimigrate\ Journal\ RegBack\ systemprofile\ TxR\ BBI BCD-Template COMPONENTS DEFAULT DRIVERS ELAM SAM SECURITY SOFTWARE SYSTEM userdiff BBI{53b39ea0-18c4-11ea-a811-000d3aa4692b}.TM.blf COMPONENTS{53b39e63-18c4-11ea-a811-000d3aa4692b}.TM.blf DEFAULT{53b39e7c-18c4-11ea-a811-000d3aa4692b}.TM.blf DRIVERS{53b39e70-18c4-11ea-a811-000d3aa4692b}.TM.blf ELAM{53b39eac-18c4-11ea-a811-000d3aa4692b}.TM.blf SAM{53b39e57-18c4-11ea-a811-000d3aa4692b}.TM.blf SECURITY{53b39e4b-18c4-11ea-a811-000d3aa4692b}.TM.blf SOFTWARE{53b39e2f-18c4-11ea-a811-000d3aa4692b}.TM.blf SYSTEM{53b39e3e-18c4-11ea-a811-000d3aa4692b}.TM.blf BCD-Template.LOG BBI.LOG1 BCD-Template.LOG1 COMPONENTS.LOG1 DEFAULT.LOG1 DRIVERS.LOG1 ELAM.LOG1 SAM.LOG1 SECURITY.LOG1 SOFTWARE.LOG1 SYSTEM.LOG1 userdiff.LOG1 .... and more Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i var  sr: TSearchRec;begin  if FindFirst('c:\windows\system32\config\*', faAnyFile, sr)=0  then    repeat      Listbox1.Items.Add(sr.Name);   until FindNext(sr)<>0;    FindClose(sr);  end;end; ---------------------------------------------------------------------- Nicole · 2022-11-01 06:20 What happens, if you start it as "ordinary user"? Sometimes stuff is shown to the current user fine, what would be expected to be seen by the admin. I have this effect in one case by the PowerShell and did not dig deeper. And: Have you checked the configuration of Lazarus about with which rights a software shall start? ---------------------------------------------------------------------- Serg7 · 2022-11-01 06:31 With the current rights, FindFirst returns an error 5. As I understand it, this is a denial of access. With admin rights, Total Commander shows files. Even for some reason, PowerShell shows less: ---------------------------------------------------------------------- bobby100 · 2022-11-01 09:09 Delphi 7 and XE had the same problem - faAnyFile wasn't covering all the files and folders. I dug my old archives and found some code that I've used in MC Shield (Delphi XE). Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i function FindFiles(Directory: String; const Files: TStrings): Integer;var  SearchRec: TSearchRec;begin  Directory := IncludeTrailingPathDelimiter(Directory);  FillChar(SearchRec, SizeOf(SearchRec), 0);  if FindFirst(Directory + '*.*', faAnyFile or $00000080, SearchRec) = 0 then  begin    try      repeat        if (SearchRec.Name <> '.') and (SearchRec.Name <> '..') then        begin          Files.Add(Directory + SearchRec.Name);          if SearchRec.Attr and faDirectory <> 0 then            FindFiles(Directory + SearchRec.Name, Files);        end;      until FindNext(SearchRec) <> 0;    finally      SysUtils.FindClose(SearchRec);    end;  end;  Result := Files.Count;end; ---------------------------------------------------------------------- KodeZwerg · 2022-11-01 09:27 Running with admin rights my method get all. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i // This method will crawl thru a folder and collect their filenames// IncludeSubFolders switch will get every filename, False by default// Based upon very fast FindEx Api (Windows)// The result will contain full path + filenamefunction FindExFiles(const BasePath: WideString; const FileMask: WideString = '*.*'; const IncludeSubFolders: Boolean = False): TStrArr;var  FindExHandle    : THandle;  Win32FindData   : TWin32FindDataW;  FindExInfoLevels: TFINDEX_INFO_LEVELS;  FindExSearchOps : TFINDEX_SEARCH_OPS;  AdditionalFlags : DWORD;  tmp, Folders    : TStrArr;  i, ii           : Integer;begin  SetLength(Result{%H-}, 0);  SetLength(Folders{%H-}, 0);  SetLength(tmp{%H-}, 0);  FindExInfoLevels := FindExInfoBasic;  FindExSearchOps  := FindExSearchLimitToDirectories;  AdditionalFlags  := FIND_FIRST_EX_LARGE_FETCH or FIND_FIRST_EX_ON_DISK_ENTRIES_ONLY;  FindExHandle     := Windows.FindFirstFileExW(                        PWideChar(IncludeTrailingBackslash(BasePath) + FileMask)                      ,FindExInfoLevels, @Win32FindData, FindExSearchOps, nil                      ,AdditionalFlags);  if (FindExHandle <> INVALID_HANDLE_VALUE) then    repeat      if ((Win32FindData.cFileName <> '.') and (Win32FindData.cFileName <> '..')) then        begin        if (0 = (Win32FindData.dwFileAttributes and FILE_ATTRIBUTE_DIRECTORY)) then            AddStrArr(Result, IncludeTrailingBackslash(BasePath) + Win32FindData.cFileName);        if (IncludeSubFolders and             (0 <> (Win32FindData.dwFileAttributes and FILE_ATTRIBUTE_DIRECTORY))) then          AddStrArr(Folders, IncludeTrailingBackslash(BasePath) + Win32FindData.cFileName);        end;    until not Windows.FindNextFileW(FindExHandle, Win32FindData);  Windows.FindClose(FindExHandle);  if IncludeSubFolders then    for i := Low(Folders) to High(Folders) do      begin        tmp := FindExFiles(Folders[i], FileMask, IncludeSubFolders);        for ii := Low(tmp) to High(tmp) do          AddStrArr(Result, tmp[ii]);      end;  SetLength(Folders, 0);  SetLength(tmp, 0);end; ---------------------------------------------------------------------- Serg7 · 2022-11-01 11:46 Tried both options. Same result as mine - only 4 folders. SysUtils actually implements the last option internally, but with zero AdditionalFlags. In this case, this flag has no effect. ---------------------------------------------------------------------- KodeZwerg · 2022-11-01 12:35 Quote from: Serg7 on November 01, 2022, 12:46:54 pmTried both options. Same result as mine - only 4 folders. SysUtils actually implements the last option internally, but with zero AdditionalFlags. In this case, this flag has no effect. The flags I use are just to speed things up and as I have mention it, on my system with administrator rights (what is a must for protected folders) it finds everything like TotalCommander does. ---------------------------------------------------------------------- Serg7 · 2022-11-01 13:25 According to the idea, if your function finds all the files, then the same thing should return on your system with FindFirst, FindNext. If it's not difficult for you, can you try the code from my first post? I tried to do the same in C++. The result is similar - 4 folders. Code: C  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i #include #include  using std::filesystem::directory_iterator; int main() {    for (const auto& file : directory_iterator("c:\\windows\\system32\\config"))        std::cout << file.path() << "\n";    return EXIT_SUCCESS;}  The first screen is the result of the C ++ program, the second is what Total Commander shows ---------------------------------------------------------------------- KodeZwerg · 2022-11-01 16:00 Feel free to checkout my other filesystem project using PIDL instead of slow findfirst etc... (it will ask for permissions when needed, no need to run as admin) https://www.donationcoder.com/forum/index.php?topic=50212.0 ---------------------------------------------------------------------- Serg7 · 2022-11-01 18:13 I tried your program. She showed all the files. But so far I have not found examples of this method of obtaining file lists ---------------------------------------------------------------------- PascalDragon · 2022-11-01 18:43 Quote from: Serg7 on November 01, 2022, 06:51:38 amSearching for files works fine, but if scan the c:\windows\system32\config\ directory, then with administrator rights it only shows folders: Journal\ RegBack\ systemprofile\ TxR\ You are on a 64-bit system, your application is compiled as 32-bit and folder redirection is enabled thus you list in fact the content of C:\Windows\SysWOW64\Config. So either compile your application as 64-bit or disable folder redirection by using Wow64DisableWow64FsRedirection before iterating the directory. ---------------------------------------------------------------------- KodeZwerg · 2022-11-01 19:31 Quote from: Serg7 on November 01, 2022, 07:13:03 pmI tried your program. She showed all the files. But so far I have not found examples of this method of obtaining file lists ( I am smiling, never saw my app showing cyrillic descriptions  ) Code is same as I showed you (from point of what results I get), on that project (made with Delphi) I warped full into the world of Windows API to get fastest results and it is far away from any "string" type results, everything you see in there is actual an object (PIDL). ( https://learn.microsoft.com/en-us/windows/win32/api/shtypes/ns- shtypes-itemidlist ) ---------------------------------------------------------------------- Serg7 · 2022-11-01 19:40 Wow64DisableWow64FsRedirection works! Thank you so much! And a big thank to everyone! I will still deal with PIDL ---------------------------------------------------------------------- d7_2_laz · 2022-11-01 21:24 I think there may be no need for the PIDL cosmos. And not for the FindFirstFileExW as well. I did read the article with interest because i felt inspired by the idea that FindFirstFileExW would speedup things. But got disappointed. A test against FindFirstFileW (which i use) did double the run time. However. Using a normal "FindFirstFileW" in my own app, laz 64bit, Win x64, started as admin user, does show all required 'protected' files. See screenshot. Without PIDL or FindFirstFileExW. ---------------------------------------------------------------------- KodeZwerg · 2022-11-01 21:38 Quote from: d7_2_laz on November 01, 2022, 10:24:29 pmA test against FindFirstFileW (which i use) did double the run time.Show your testcode please. My guess is, you plain called my method and measured time, than your method (where everything is already cached) ... ---------------------------------------------------------------------- d7_2_laz · 2022-11-01 21:55 That's nearly right. Adapted in so far as i skipped the TStrArr stuff that i didn't know yet and used a simple StringList instead for testing. I'm aware and feel that it might be the case that the usage of the FindFirstFileExW could be improved somwhow (looking at the diverse parameters!). But caching doesn't play a role (repeated tests on a bigger folder in vice verse order). ---------------------------------------------------------------------- KodeZwerg · 2022-11-01 22:05 https://forum.lazarus.freepascal.org/index.php/topic,60480.msg452595.h tml#msg452595 Here you can see a full project using my shown method.