How to open Folder and select item? lazarus / 21-General ---------------------------------------------------------------------- majid.ebru · 2022-06-07 03:44 Hi dear When I right-click an icon on the Windows desktop and open the file location, I go to the destination folder and then to the selected icon. how can i implement this? I can only open a folder or open a program like these code: 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   OpenURL(edtDirectory.Text+'\'+Rd_Name);  SysUtils.ExecuteProcess(UTF8ToSys('explorer.exe'), stg100.Cells[2,stg100.Row], \['\']);// <= what is this ???  WinExec(PChar('explorer.exe /e,'+ stg100.Cells[2,stg100.Row]),SW_SHOWNORMAL); but I can't select the target icon? ---------------------------------------------------------------------- Coldzer0 · 2022-06-07 04:40 Here's a very simple way of doing this  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 Program OpenFileLocation; Uses  Windows,  shlobj,  ActiveX; Var  SelectedFile : LPITEMIDLIST;Begin  CoInitializeEx(nil, COINIT_MULTITHREADED);  Try    SelectedFile := ILCreateFromPath('C:\Windows\System32\cmd.exe');    If SelectedFile <> nil Then    Begin      SHOpenFolderAndSelectItems(SelectedFile, 0, SelectedFile, 0);      ILFree(SelectedFile);    End;  Finally    CoUninitialize;  End;End. ---------------------------------------------------------------------- majid.ebru · 2022-06-07 08:49 thank you Coldzer0 but i should change this code: 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 SelectedFile := ILCreateFromPath(PChar( myAddress )); ---------------------------------------------------------------------- loaded · 2022-06-07 09:17 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 procedure TForm1.Button1Click(Sender: TObject);begin   ExecuteProcess('explorer.exe', '/select,'+PChar('C:\Windows\System32\cmd.exe'), []);end; ---------------------------------------------------------------------- majid.ebru · 2022-08-10 11:07 Quote from: loaded on June 07, 2022, 11:17:39 amCode: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.Button1Click(Sender: TObject);begin   ExecuteProcess('explorer.exe', '/select,'+PChar('C:\Windows\System32\cmd.exe'), []);end; thank you but last code is faster that this code ---------------------------------------------------------------------- majid.ebru · 2024-08-28 06:07 Hi please help and guide me if file names contain UTF8 char , this code does not open the file? Quote from: Coldzer0 on June 07, 2022, 06:40:01 amHere's a very simple way of doing this  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 Program OpenFileLocation; Uses  Windows,  shlobj,  ActiveX; Var  SelectedFile : LPITEMIDLIST;Begin  CoInitializeEx(nil, COINIT_MULTITHREADED);  Try    SelectedFile := ILCreateFromPath('C:\Windows\System32\cmd.exe');    If SelectedFile <> nil Then    Begin      SHOpenFolderAndSelectItems(SelectedFile, 0, SelectedFile, 0);      ILFree(SelectedFile);    End;  Finally    CoUninitialize;  End;End. ---------------------------------------------------------------------- majid.ebru · 2024-09-08 12:07 Hi please help and guide me ---------------------------------------------------------------------- Wallaby · 2024-09-08 12:14 Use the Unicode APIs: 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  SelectedFile: PItemIDList;Begin  CoInitializeEx(nil, COINIT_MULTITHREADED);  Try    SelectedFile := ILCreateFromPathW(PWideChar(UTF8Decode('Z:\temp\хуй.pdf')));    If SelectedFile <> nil Then    Begin      SHOpenFolderAndSelectItems(SelectedFile, 0, SelectedFile, 0);      ILFree(SelectedFile);    End;  Finally    CoUninitialize;  End;End. ---------------------------------------------------------------------- paweld · 2024-09-08 12:28 you can solve this in 2 ways: - way one is to change the code page from UTF8 to Windows - you need to add the LazUTF8 unit to the uses section, and to the dependencies you need to add the LCLBase or LCL package (if there is none) - way two is to replace the path with WideString and use ILCreateFromPathWCode: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program OpenFileLocation; uses  Windows, shlobj, ActiveX,  {LazUTF8} //uncomment for way 1  ; var  SelectedFile: LPITEMIDLIST;begin  CoInitializeEx(nil, COINIT_MULTITHREADED);  try  ////way1    //SelectedFile := ILCreateFromPath(PChar(UTF8ToWinCP(ParamStr(0))));    //way 2    SelectedFile := ILCreateFromPathW(PWideChar(WideString(ParamStr(0))));    if SelectedFile <> nil then    begin      SHOpenFolderAndSelectItems(SelectedFile, 0, SelectedFile, 0);      ILFree(SelectedFile);    end;  finally    CoUninitialize;  end;end. ---------------------------------------------------------------------- Remy Lebeau · 2024-09-08 23:57 Quote from: paweld on September 08, 2024, 02:28:48 pm- way two is to replace the path with WideString ... Or better, UnicodeString.  You should stay away from WideString when you are not interacting directly with ActiveX/COM objects.  UnicodeString is more efficient than WideString for non-COM work.  You don't need COM to use ILCreateFromPathW() or SHOpenFolderAndSelectItems().