Extract path from active explorer window lazarus / 34-Windows ---------------------------------------------------------------------- LemonParty · 2025-11-04 13:33 Hello. Does anybody have a code to extract path from active explorer window? ---------------------------------------------------------------------- Thaddy · 2025-11-04 14:09 Outside or inside the program? From the TOpenDialog (which encapsulates the explorer) it is simply reading the property Filename.... For the explorer itself (windows assumed) you need the COM library for explorer, which you can generate from the explorer itself. ---------------------------------------------------------------------- LemonParty · 2025-11-04 14:25 I guess it is a second variant. I have an explorer window (active) and I want to extract the location on where this window is opened. And you right it needs COM library. ---------------------------------------------------------------------- Thaddy · 2025-11-04 15:13 You can import that from explorer.exe. ---------------------------------------------------------------------- LemonParty · 2025-11-05 14:16 Here is a code in C#: 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     IntPtr MyHwnd = FindWindow(null, "Directory");    var t = Type.GetTypeFromProgID("Shell.Application");    dynamic o = Activator.CreateInstance(t);    try    {        var ws = o.Windows();        for (int i = 0; i < ws.Count; i++)        {            var ie = ws.Item(i);            if (ie == null || ie.hwnd != (long)MyHwnd) continue;            var path = System.IO.Path.GetFileName((string)ie.FullName);            if (path.ToLower() == "explorer.exe")            {                var explorepath = ie.document.focuseditem.path;            }        }    }    finally    {        Marshal.FinalReleaseComObject(o);    }Can someone help to translate it to Pascal? ---------------------------------------------------------------------- paweld · 2025-11-06 04:56 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 uses  Variants, Windows, ActiveX, ComObj, ShlObj; procedure TForm1.Button1Click(Sender: TObject);var  ShellApp: Variant;  WS: Variant;  IE: Variant;  Path, ExplorePath: WideString;  i: Integer;begin  ShellApp := CreateOleObject('Shell.Application');  try    WS := ShellApp.Windows;    for i := 0 to WS.Count - 1 do    begin    IE := WS.Item(i);      if VarIsNull(IE) then        continue;      Path := ExtractFileName(WideString(IE.FullName));      if LowerCase(Path) = 'explorer.exe' then      begin        ExplorePath := IE.Document.Folder.Self.Path; //current directory or selected object (file/dir): IE.Document.FocusedItem.Path;        Memo1.Lines.Add(ExplorePath);      end;    end;  finally    ShellApp := Unassigned;  end;end; ---------------------------------------------------------------------- LemonParty · 2025-11-06 08:41 Thank you very much. Here is checked function, that extract path from active window: 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 GetActivePath: String;{$IfDef Windows}var  H: THandle;  ShellApp: Variant;  WS: Variant;  IE: Variant;  Path, ExplorePath: WideString;  i: Integer;begin  Result:= '';  H:= GetForegroundWindow;  ShellApp := CreateOleObject('Shell.Application');  try    WS := ShellApp.Windows;    for i := 0 to WS.Count - 1 do begin      IE := WS.Item(i);      if VarIsNull(IE) then        continue;      Path := ExtractFileName(WideString(IE.FullName));      if (LowerCase(Path) = 'explorer.exe') and (H = IE.hwnd) then begin        ExplorePath := IE.Document.Folder.Self.Path; //current directory or selected object (file/dir): IE.Document.FocusedItem.Path;        Result:= UTF8Encode( ExplorePath );        Break;      end;    end;  finally    ShellApp := Unassigned;  end;end;{$Else}begin end;{$EndIf}