Results 1 to 8 of 8

Thread: [RESOLVED] How to get a ftp folder shortcut to behave as a folder in explorer?

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2023
    Posts
    940

    Resolved [RESOLVED] How to get a ftp folder shortcut to behave as a folder in explorer?

    I have runned out of ideas how to make the shortcuts to behave as folders (browsable in the tree pane).
    I have come so far as they look and feel very similiar in the listview (browsable on dblclick).
    I have not attached any code because it's the standard procedure used but pointing to a ftp url istead.
    Maybe I need a different approach?
    The shortcut to the left is mine and the one to the right is explorer's shortcut.
    Attached Images Attached Images  

  2. #2
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    6,835

    Re: How to get a ftp folder shortcut to behave as a folder in explorer?

    They might look the same but *are they* the same? Is the second a .url instead of a .lnk? (Both are similar in that .url is 'always hidden' like .lnk)

    If you created it in Explorer by using 'New shortcut' then look at the properties-- that creates a 'New Internet Shortcut' .url file, not a .lnk, if you enter an internet address.

    You can create .url shortcuts with the InternetShortcut coclass (CLSID_InternetShortcut), which you query for IUniformResourceLocatorW, call .SetURL, and save with IPersistFile like you would a regular shortcut. Everything you need is available in oleexp.tlb and WinDevLib.
    Last edited by fafalone; Feb 1st, 2025 at 12:25 AM.

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2023
    Posts
    940

    Re: How to get a ftp folder shortcut to behave as a folder in explorer?

    Quote Originally Posted by fafalone View Post
    They might look the same but *are they* the same? Is the second a .url instead of a .lnk? (Both are similar in that .url is 'always hidden' like .lnk)

    If you created it in Explorer by using 'New shortcut' then look at the properties-- that creates a 'New Internet Shortcut' .url file, not a .lnk, if you enter an internet address.

    You can create .url shortcuts with the InternetShortcut coclass (CLSID_InternetShortcut), which you query for IUniformResourceLocatorW, call .SetURL, and save with IPersistFile like you would a regular shortcut. Everything you need is available in oleexp.tlb and WinDevLib.


    I tried to only use the CLSID_Internetshortcut this time with the prefix .url and not .lnk (the .lnk prefix didn't work at all with CLSID_Internetshortcut)


    Code:
       Dim pidlNetHood As Long
       Dim lpNetHoodPath As Long
       Dim pISI As IShellItem2
       Dim pISI_NetHood As IShellItem2
       Dim pISLW As IShellLinkW
       Dim sWrkPath As String
       Dim lpName As Long
       Dim sName As String
       Dim pIPF As IPersistFile
       Dim pIURL As IUniformResourceLocatorW
    
       pidl = ILCreateFromPath(StrPtr(sURL))
       hr = ShCreateNewShellItem(pidl, pISI)
       If (pidl <> 0) And (hr = S_OK) Then
          pISI.GetDisplayName SIGDN_NORMALDISPLAY, lpName
          sName = GetStrAFromStrPtrW(lpName)
          hr = SHGetKnownFolderIDList(ByVal VarPtr(FOLDERID_NetHood), KF_FLAG_DEFAULT, 0, pidlNetHood)
          ShCreateNewShellItem pidlNetHood, pISI_NetHood
          pISI_NetHood.GetDisplayName SIGDN_DESKTOPABSOLUTEPARSING, lpNetHoodPath
          sWrkPath = GetStrAFromStrPtrW(lpNetHoodPath)
    
    'COMMENTING OUT THE STANDARD .LNK CREATION
    '      hr = ShGetShellLinkW(pISLW)
    '      pISLW.SetWorkingDirectory sWrkPath & "\" & sName
    '      'pISLW.SetIDList pidl
    '      pISLW.SetDescription sName
    '      pISLW.SetIconLocation GetSysDir & "\imageres.dll", 68
    '      pISLW.SetPath sURL
    '      pISLW.SetRelativePath sURL, 0
          
          SHCreateInternetShortCut pIURL
          pIURL.SetUrl sURL, IURL_SETURL_FL_USE_DEFAULT_PROTOCOL
          
          Set pIPF = pIURL
          pIPF.Save sWrkPath & "\" & sName & ".url", 1
    
          CoTaskMemFree lpName
          CoTaskMemFree lpNetHoodPath
       End If
    This is totally wrong approach, wrong behavior and wrong icon.
    By dbl-clicking the url the command window enumerates the content of the url.
    And combining it with ShellLink object is out of the question.

    When checking the properties for the shortcut explorer created it shows it's a folder shortcut. Or a shortcut behaving as a folder as I stated in the #1
    Attached Images Attached Images    
    Last edited by nebeln; Feb 1st, 2025 at 06:26 AM.

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2023
    Posts
    940

    Re: How to get a ftp folder shortcut to behave as a folder in explorer?

    I have also now recently tried combine the creation with following there the &H1 flag is Folder but no success.
    Yes, it creates a folder shortcut but it's invalid.
    And do you put this function before the shelllink creation it becomes overwritten.

    Code:
    Public Declare Function CreateSymbolicLink Lib "kernel32" Alias "CreateSymbolicLinkA" (ByVal lpSymlinkFileName As String, ByVal lpTargetFileName As String, ByVal dwFlags As Long) As Long
    
    lr = CreateSymbolicLink(sWrkPath & "\" & sName, sURL, &H1)

  5. #5
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    6,835

    Re: How to get a ftp folder shortcut to behave as a folder in explorer?

    Quote Originally Posted by nebeln View Post
    I tried to only use the CLSID_Internetshortcut this time with the prefix .url and not .lnk (the .lnk prefix didn't work at all with CLSID_Internetshortcut)


    Code:
       Dim pidlNetHood As Long
       Dim lpNetHoodPath As Long
       Dim pISI As IShellItem2
       Dim pISI_NetHood As IShellItem2
       Dim pISLW As IShellLinkW
       Dim sWrkPath As String
       Dim lpName As Long
       Dim sName As String
       Dim pIPF As IPersistFile
       Dim pIURL As IUniformResourceLocatorW
    
       pidl = ILCreateFromPath(StrPtr(sURL))
       hr = ShCreateNewShellItem(pidl, pISI)
       If (pidl <> 0) And (hr = S_OK) Then
          pISI.GetDisplayName SIGDN_NORMALDISPLAY, lpName
          sName = GetStrAFromStrPtrW(lpName)
          hr = SHGetKnownFolderIDList(ByVal VarPtr(FOLDERID_NetHood), KF_FLAG_DEFAULT, 0, pidlNetHood)
          ShCreateNewShellItem pidlNetHood, pISI_NetHood
          pISI_NetHood.GetDisplayName SIGDN_DESKTOPABSOLUTEPARSING, lpNetHoodPath
          sWrkPath = GetStrAFromStrPtrW(lpNetHoodPath)
    
    'COMMENTING OUT THE STANDARD .LNK CREATION
    '      hr = ShGetShellLinkW(pISLW)
    '      pISLW.SetWorkingDirectory sWrkPath & "\" & sName
    '      'pISLW.SetIDList pidl
    '      pISLW.SetDescription sName
    '      pISLW.SetIconLocation GetSysDir & "\imageres.dll", 68
    '      pISLW.SetPath sURL
    '      pISLW.SetRelativePath sURL, 0
          
          SHCreateInternetShortCut pIURL
          pIURL.SetUrl sURL, IURL_SETURL_FL_USE_DEFAULT_PROTOCOL
          
          Set pIPF = pIURL
          pIPF.Save sWrkPath & "\" & sName & ".url", 1
    
          CoTaskMemFree lpName
          CoTaskMemFree lpNetHoodPath
       End If
    This is totally wrong approach, wrong behavior and wrong icon.
    By dbl-clicking the url the command window enumerates the content of the url.
    And combining it with ShellLink object is out of the question.

    When checking the properties for the shortcut explorer created it shows it's a folder shortcut. Or a shortcut behaving as a folder as I stated in the #1
    The code you wrote seems entirely unrelated to the method I described. I said nothing about known folders,"network neighborhood" win9x stuff, shell items, or pidls, yet you're doing something with all 4, and if you wrote any code related to it, didn't include the key part InternetShortcut.

    also as noted .lnk and .url are different things, of course you don't use the .lnk extension for .url files.

    finally if you created the shortcut to ftp.sunet.se some other way besides 'New shortcut' then I have no idea what you did or what it is. You'll need to start over and explain because entering ftp://ftp.sunet.se in the Explorer address bar isn't creating a nav tree entry for me and the address bar item isn't draggable to create a shortcut.

    Symbolic links are different from anything so far discussed and afaik can't point to internet locations.
    Last edited by fafalone; Feb 1st, 2025 at 10:14 AM.

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2023
    Posts
    940

    Re: How to get a ftp folder shortcut to behave as a folder in explorer?

    Here is the answer to to this question I just recently cracked.
    The problem was the routine created shortcutfiles and not folders.

    Code:
    First replace this line of code
    hr = ShGetShellLinkW(pISLW)  
    
    and replace it with following:
    hr = SHCreateFolderShortCut(pISLW)   '<--- This one creates the correct folder shortcut.
    Code:
    Public Const sCLSID_FolderShortcut As String = "{0AFACED1-E828-11D1-9187-B532F1E9575D}"
    
    Public Function SHCreateFolderShortCut(ByRef pISLW As IShellLinkW) As Long
       Static CLSID_FolderShortcut As GUID
       
       CLSIDFromString StrPtr(sCLSID_FolderShortcut), CLSID_FolderShortcut
       SHCreateFolderShortCut = CoCreateInstance(CLSID_FolderShortcut, 0&, CLSCTX_INPROC_SERVER, IID_IShellLinkW, pISLW)
    End Function
    And below is the fully reworked function for creating ftp folder shortcuts to show up in your Explorer.

    This feature is actually undocumented by Microsoft.

    Code:
    Public Function ShGetShellFolderFromURL(ByVal sURL As String, Optional ByRef pISF_URL As IShellFolder2) As Long
       Dim pIPFldr As IPersistFolder3
       Dim pIPFile As IPersistFile
       Dim pISLW As IShellLinkW
       Dim pidlWd As Long
       Dim lWd As Long
       Dim sWd As String
       Dim pISIWd As IShellItem2
       Dim pidlURL As Long
       Dim lURL As Long
       Dim sURLName As String
       Dim pISIURL As IShellItem2
       Dim lpPFTI As PERSIST_FOLDER_TARGET_INFO
       Dim pIBCTX As IBindCtx
       Dim pidlNew As Long
       
       'Create the folder shortcut
       SHCreateFolderShortCut pISLW
       
       'Working Directory for the folder shortcut
       ShGetItemIdFromKnownFolder "{C5ABBF53-E17F-4121-8900-86626FC2C973}", pidlWd
       ShGetShellItem pidlWd, pISIWd
       pISIWd.GetDisplayName SIGDN_DESKTOPABSOLUTEPARSING, lWd
       sWd = GetStrAFromStrPtrW(lWd)
       
       'The ftp-URL itself
       pidlURL = ILCreateFromPathW(StrPtr(sURL))
       ShGetShellItem pidlURL, pISIURL
       pISIURL.GetDisplayName SIGDN_NORMALDISPLAY, lURL
       sURLName = GetStrAFromStrPtrW(lURL)
       
       'Setting up the folder shortcut itself
       pISLW.SetIconLocation GetSysDir & "\imageres.dll", 68
       pISLW.SetWorkingDirectory lWd
       pISLW.SetDescription sURL
       pISLW.SetPath sURL
       pISLW.SetIDList pidlURL
       pISLW.SetRelativePath sURL, 0
       
       Set pIPFldr = pISLW
          
       Set pIPFile = pIPFldr
       
       sURL = Replace(sURL, Left(sURL, 6), "")
       
       pIPFile.Save sWd & "\" & sURL, 1
       
       pidlNew = ILCreateFromPathW(StrPtr(sWd & "\" & sURL))
       
       CreateBindCtx 0&, pIBCTX
       
    '   lpPFTI.pidlTargetFolder = pidlURL
    '   lpPFTI.szNetworkProvider(0) = Asc("dmi.dk")
    '   lpPFTI.szTargetParsingName(0) = Asc("ftp://ftp.dmi.dk")
    '   lpPFTI.dwAttributes = FILE_ATTRIBUTE_DIRECTORY
    '   lpPFTI.csidl = CSIDL_FLAG_CREATE
    '
    '   For any reason InitializeEx raising automation error.
    '   pIPFldr.InitializeEx pIBCTX, pidlNew, lpPFTI
       pIPFldr.Initialize pidlNew
       
    '  Outgoing IShellFolder2 for the ftp folder you can do some handy with
       hr = pISIURL.BindToHandler(ByVal ObjPtr(pIBCTX), BHID_SFObject, IID__IShellFolder, pISF_URL)
       
        CoTaskMemFree pidlURL
        pidlURL = 0
        CoTaskMemFree lURL
        lURL = 0
        CoTaskMemFree lWd
        lWd = 0
        CoTaskMemFree pidlWd
        pidlWd = 0
        CoTaskMemFree pidlNew
        pidlNew = 0
        Set pISIWd = Nothing
        Set pISIURL = Nothing
        Set pISLW = Nothing
        Set pIBCTX = Nothing
    End Function
    Attached Images Attached Images  
    Last edited by nebeln; Feb 7th, 2025 at 07:00 AM.

  7. #7
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    6,835

    Re: [RESOLVED] How to get a ftp folder shortcut to behave as a folder in explorer?

    Seems the coclasses for that were missing from oleexp and WinDevLib were missing FolderShortcut; added for next release.

  8. #8

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2023
    Posts
    940

    Re: [RESOLVED] How to get a ftp folder shortcut to behave as a folder in explorer?

    Quote Originally Posted by fafalone View Post
    Seems the coclasses for that were missing from oleexp and WinDevLib were missing FolderShortcut; added for next release.
    Probably I should bumped you in your oleexp thread?
    However you know it know.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width