topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Saturday June 12, 2021, 9:01 am
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: IDEA: Pull icon from exe and put on the containing folder  (Read 2142 times)

kunkel321

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 549
    • View Profile
    • Donate to Member
IDEA: Pull icon from exe and put on the containing folder
« on: February 09, 2021, 11:54 AM »
I have a Portable setup on my work computer (not sure if that's relevant to the request).  As seen in the back window, I have a PortableApps folder.  For the most part, there is a subfolder for each portable app.  And--mostly--each folder has an exe in it of the application, for example Calibre Portable in the front window.  I was simply going through and manually customizing the folder by navigating to the exe file and choosing the first image that is compiled in it.  That way, the folder has the same image as the application in it.  I figured that could be automated with AHK, or some other language...

I guess the rules would be:
-look inside of folder for the first exe file found.
-look for first icon resource in that found exe file.
-set the folder's icon to be that icon resouce.

snack idea 2-9-2021.pngIDEA:  Pull icon from exe and put on the containing folder

Any takers?   :P

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 40,541
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
Re: IDEA: Pull icon from exe and put on the containing folder
« Reply #1 on: February 09, 2021, 01:05 PM »
That's a nice idea.. I have some code to pull an icon from an exe.. Wouldn't be too hard to do adapt the code, but hopefully a standalone tool already exists for this?

skwire

  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 5,235
    • View Profile
    • Donate to Member
Re: IDEA: Pull icon from exe and put on the containing folder
« Reply #2 on: February 09, 2021, 01:26 PM »
That's a nice idea.. I have some code to pull an icon from an exe.

There's no need to extract the icon as this is done via hidden "desktop.ini" files within the folder in question.  Here's a sample:

Code: Text [Select]
  1. [.ShellClassInfo]
  2. IconResource=C:\path\to\program\program.exe,0
  3. [ViewState]
  4. Mode=
  5. Vid=
  6. FolderType=Generic

https://hwiegman.hom...l.nl/desktopini.html

kunkel321

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 549
    • View Profile
    • Donate to Member
Re: IDEA: Pull icon from exe and put on the containing folder
« Reply #3 on: February 09, 2021, 01:56 PM »
Interesting.  So what you'd need to do I guess is just identify the path of the exe, then edit the 'desktop.ini.' 

Edit to idea/request:
As I look through my subfolders, I see that some of the applications have secondary exe files in with the main application.  Often those have different icons.  As such, the "first" exe found is not always the correct one.  Perhaps the solution to this, would be to find the exe that has the same name as the folder.  Unfortunately, the exe's name is often slightly different. 

Maybe it would make sense to navagate to the correct exe, then select it and activate the tool (via hotkey I guess).  The tool would then get the path to that exe, then edit the parent folder's desktop.ini folder... 

EDIT:  On a related, but different topic:  About 10 years ago, a fellow named Kilmatead, made a tool in AutoIt for customizing folder icons.  It is here
https://forum.zabkat....php?f=22&t=8816
I just checked and the download still works.  And the app works on my current Win 10 laptop. 

Lots of options.  Sadly Kilmatead disappeared from the forums years ago and is assumed, either dead, or abducted by aliens. 

MilesAhead

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 7,649
    • View Profile
    • Miles Ahead Software
    • Donate to Member
Re: IDEA: Pull icon from exe and put on the containing folder
« Reply #4 on: February 09, 2021, 03:19 PM »
If you wish to do this with a lot of folders it may be worth checking out a macro record/playback utility.  If you select the exe in the folder then start recording mouse actions and keystrokes you could play it back on other selected exe files.  In my W10 explorer shift right click brings up the context menu that has "copy as path."  After clicking that pressing Alt up arrow will move you up in explorer so that the containing folder is selected.  Right click and click Customize tab, then click Change Icon.   Click browse button.  Now you can paste in the path of the exe that is in the clipboard.

If you only have a hundred or so folders you wish to customize, assuming the macro playback works, you could do 10 at a time until they are all customized.  If you have hundreds of folders then yes you may want to try to find a dedicated utility somewhere.

kunkel321

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 549
    • View Profile
    • Donate to Member
Re: IDEA: Pull icon from exe and put on the containing folder
« Reply #5 on: February 09, 2021, 04:26 PM »
... it may be worth checking out a macro record/playback utility. ...
Actually I only figured I'd do one folder at a time, so yea a macro makes sense. 

I did some googling, and it appears that Win 10 can capture a file's path via Shift+RightClick.  I'm trying to simulate that in AutoHotkey.  Windows doesn't seem to be seeing the "Shift" part though...  :- /

Code: Autohotkey [Select]
  1. !^g::
  2. sleep, 1000
  3. Send, {LButton Down}
  4. sleep, 100
  5. Send, {LButton Up}
  6. sleep, 100
  7. Send, {Shift Down}
  8. Send, {RButton Down}
  9. sleep, 100
  10. Send, {Shift Up}
  11. Send, {RButton Up}
  12. return

EIDT:  This works!

Code: Autohotkey [Select]
  1. !^g::
  2. sleep, 1000
  3. sleep, 100
  4. Send, {Shift Down}
  5. sleep, 100
  6. Click, Right
  7. sleep, 100
  8. Send, {Shift Up}
  9. return

EDIT2:
This is the most kludgy thing I've seen in a while...  And its unreliability attests to this!  LOL
I got tiried of working on it.  I might try to finish it later.

Code: Autohotkey [Select]
  1. #NoEnv ; For security
  2.  
  3. ;Navigate to file in Win Explorer.  Hover mouse over file.
  4. !^g::
  5. sleep, 1000
  6. Click ;Selects file
  7. sleep, 100
  8. Send, {Shift Down}
  9. sleep, 100
  10. Click, Right ;Pops up special context menu with "Copy as path."
  11. sleep, 100
  12. Send, {Shift Up}
  13. Send aaa{Enter} ;Need correct number of a's to select Copy as path.
  14. sleep, 100
  15.  
  16. Send, {Alt Down}
  17. sleep, 100
  18. send, {Up} ;Tells Wind Explorer to browse up one level.
  19. sleep, 100
  20. Send, {Alt Up}
  21. sleep, 100
  22.  
  23. Send, {AppsKey} ;Parent folder will be selected.  Shows context menu.
  24.  
  25. sleep, 100
  26. Send, {Up} ;Goes to bottom memu item (which is Properties.)
  27. sleep, 100
  28. Send, {Enter}
  29. Send, {Shift Down}
  30. sleep, 100
  31. send, {Tab} ;ShiftTabTab highlights General tab in Properties dialog.
  32. sleep, 100
  33. send, {Tab}
  34. sleep, 100
  35. Send, {Shift Up}
  36. ;Still needs to ArrowLeft 5x to highlight Customize tab.
  37. ;Then Alt+i to change icon. Icon resource path box will be highlighted.
  38. ;Paste path into box and {Enter}.
  39.  
  40. return
« Last Edit: February 09, 2021, 05:14 PM by kunkel321 »

c.gingerich

  • Supporting Member
  • Joined in 2011
  • **
  • Posts: 733
    • View Profile
    • The Blind House
    • Donate to Member
Re: IDEA: Pull icon from exe and put on the containing folder
« Reply #6 on: February 09, 2021, 04:44 PM »
Not sure if this is what you wanted: https://www.nirsoft..../utils/iconsext.html

Never mind... Didn't fully read your post.

MilesAhead

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 7,649
    • View Profile
    • Miles Ahead Software
    • Donate to Member
Re: IDEA: Pull icon from exe and put on the containing folder
« Reply #7 on: February 10, 2021, 09:23 AM »
Maybe one of these freewares will be easier than coding it yourself?  :)

publicdomain

  • Honorary Member
  • Joined in 2019
  • **
  • Posts: 260
  • Call me Vic!
    • View Profile
    • PublicDomainGift.com
    • Read more about this member.
    • Donate to Member
Re: IDEA: Pull icon from exe and put on the containing folder
« Reply #8 on: February 10, 2021, 05:01 PM »
Any takers?   :P

I'm in! Chances are "AppFolderIcon" gets completed tomorrow / in a couple.

 :Thmbsup:

Vic
♥♥♥ You may support this project by expressing your excitement in the form of a Donation using DonationCredits, via Paypal @ PayPal.me/victorvls or by becoming a Patron @ Patreon.com/publicdomain

Thanks & keep on rocking!
Email: publicdomainvicgmail.com

Coding: AppFolderIcon v0.2.0
--Victor

4wd

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 5,506
    • View Profile
    • Donate to Member
Re: IDEA: Pull icon from exe and put on the containing folder
« Reply #9 on: February 10, 2021, 08:36 PM »
Using skwire's info, this should work if you go via Send To or the context menu if you add it in the registry ... can't test it, I'm sitting in a car  :P

Code: PowerShell [Select]
  1. # FolIco.ps1
  2.  
  3. param (
  4.   [Parameter(Mandatory = $true)][string]$file
  5. )
  6. $deskini = "$(Split-Path "$($file)" -Parent)\desktop.ini"
  7. $ini = "[.ShellClassInfo]`nIconFile=`"$($file)`"`nIconIndex=0`n[ViewState]`nMode=`nVid=`nFolderType=Generic"
  8. $ini | Out-File -LiteralPath "$($deskini)" -Force
  9. (Get-Item -LiteralPath "$($deskini)").Attributes = 'Hidden'

Shortcut in the archive to put in C:\Users\<user>\AppData\Roaming\Microsoft\Windows\SendTo
« Last Edit: February 10, 2021, 11:24 PM by 4wd »

Nod5

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,122
    • View Profile
    • Donate to Member
Re: IDEA: Pull icon from exe and put on the containing folder
« Reply #10 on: February 11, 2021, 04:39 AM »
Neat idea, so I made an AutoHotkey version with a hotkey and also a command line mode for easy use from FARR.

Uses COM to get the focused file's path more reliably than sending keys to the context menu.
Uses SHGetSetFolderCustomSettings method which makes the new folder icon show immediately, see Microsoft doc.

Code: Autohotkey [Select]
  1. SetWorkingDir %A_ScriptDir%
  2.  
  3. ; SetExplorerFolderIcon.ahk
  4. ; 2021-02-11
  5. ; by Nod5
  6. ; In Explorer press [F8] to set the focused file's first icon as parent folder icon
  7. ; -----------------------------------
  8. ; Default mode:
  9. ;   Select a file in Explorer and press [F8].
  10. ;   To close the script right click its tray menu icon and Exit.
  11.  
  12. ; Command line mode:
  13. ;   Pass as parameter a HWND window handle to a specific Explorer window
  14. ;   to act on that window's focused file and parent folder.
  15. ;
  16. ; Optional: use this script from FARR (Find And Run Robot)
  17. ;   Create a FARR alias and use this as the result line (modify the path):
  18. ;   Set Explorer parent folder icon | C:\some\folder\SetExplorerFolderIcon.ahk %LASTHWND%
  19. ; -----------------------------------
  20.  
  21. ; if parameter is Explorer HWND then act on that window and exit
  22. if (vHwnd := A_Args[1])
  23. {
  24.   if WinExist("ahk_class CabinetWClass ahk_id " vHwnd)
  25.     GetFocusedFileSetIcon(vHwnd)
  26. }
  27. ; else hotkey mode: create Explorer hotkey and await user action
  28. else
  29. {
  30.   Hotkey, IfWinActive, ahk_class CabinetWClass
  31.   Hotkey, F8, GetFocusedFileSetIcon
  32. }
  33. return
  34.  
  35. GetFocusedFileSetIcon(vHwnd := "")
  36. {
  37.   vFile := ExplorerGetFocusedFilepath(vHwnd)
  38.   if FileExist(vFile)
  39.   {
  40.     SplitPath, vFile, , vFolder
  41.     SetFolderIcon(vFolder, vFile, 0)
  42.   }
  43. }
  44.  
  45.  
  46. ; function: ExplorerGetFocusedFilepath(vHwnd := "")  v210211
  47. ; return filepath of focused item in vHwnd (or active) Explorer window
  48. ExplorerGetFocusedFilepath(vHwnd := "")
  49. {
  50.   vHwnd := vHwnd ? vHwnd : WinActive("A")
  51.   if vHwnd and WinExist("ahk_class CabinetWClass ahk_id " vHwnd)
  52.     for Window in ComObjCreate("Shell.Application").Windows
  53.       if (Window.HWND = vHwnd)
  54.         ; https://docs.microsoft.com/en-us/windows/win32/shell/shellfolderview-focuseditem
  55.         return vFile := Window.Document.FocusedItem.Path
  56. }
  57.  
  58.  
  59. ; function: SetFolderIcon() update Explorer folder icon in desktop.ini via SHGetSetFolderCustomSettings
  60. ; by teadrinker 2017-10-09 https://www.autohotkey.com/boards/viewtopic.php?p=174984#p174984
  61. ; https://docs.microsoft.com/en-us/windows/win32/api/shlobj_core/nf-shlobj_core-shgetsetfoldercustomsettings
  62. ; https://docs.microsoft.com/en-us/windows/win32/api/shlobj_core/ns-shlobj_core-shfoldercustomsettings
  63. SetFolderIcon(folderPath, iconPath, iconIndex)  {
  64.    static FCSM_ICONFILE := 0x10, FCS_FORCEWRITE := 0x2
  65.    if !A_IsUnicode  {
  66.       VarSetCapacity(WiconPath, StrPut(iconPath, "UTF-16")*2, 0)
  67.       StrPut(iconPath, &WiconPath, "UTF-16")
  68.    }
  69.    VarSetCapacity(SHFOLDERCUSTOMSETTINGS, size := 4*5 + A_PtrSize*10, 0)
  70.    NumPut(size, SHFOLDERCUSTOMSETTINGS)
  71.    NumPut(FCSM_ICONFILE, SHFOLDERCUSTOMSETTINGS, 4)
  72.    NumPut(A_IsUnicode ? &iconPath : &WiconPath, SHFOLDERCUSTOMSETTINGS, 4*2 + A_PtrSize*8)
  73.    NumPut(iconIndex, SHFOLDERCUSTOMSETTINGS, 4*2 + A_PtrSize*9 + 4)
  74.    DllCall("Shell32\SHGetSetFolderCustomSettings", Ptr, &SHFOLDERCUSTOMSETTINGS, WStr, folderPath, UInt, FCS_FORCEWRITE)
  75. }
  76.  
  77. ; -----------------------------------
  78. ; notes on desktop.ini files
  79. ; -----------------------------------
  80. ; https://docs.microsoft.com/en-us/windows/win32/shell/how-to-customize-folders-with-desktop-ini
  81. ; "text file that allows you to specify how a file system folder is viewed."
  82. ; See also https://hwiegman.home.xs4all.nl/desktopini.html
  83.  
  84. ; Format:
  85. ; -----
  86. ; [.ShellClassInfo]
  87. ; IconResource=C:\test\file.exe,0     ; <filepath, icon-index>
  88. ; -----
  89. ; To remove the custom folder icon delete desktop.ini
  90.  
  91. ; If we just write the file then the new folder icon does not show immediately (must close/reopen Explorer)
  92. ; If we instead use SHGetSetFolderCustomSettings the new icon shows immediately.
  93. ; SHGetSetFolderCustomSettings also hides the desktop.ini file.
  94. ; https://docs.microsoft.com/en-us/windows/win32/api/shlobj_core/nf-shlobj_core-shgetsetfoldercustomsettings
  95. ; https://docs.microsoft.com/en-us/windows/win32/api/shlobj_core/ns-shlobj_core-shfoldercustomsettings
  96. ; AutoHotkey function: SetFolderIcon()
  97. ; by Teadrinker 2017-10-09 https://www.autohotkey.com/boards/viewtopic.php?p=174984#p174984
  98. ; -----------------------------------
« Last Edit: February 11, 2021, 04:48 AM by Nod5 »

kunkel321

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 549
    • View Profile
    • Donate to Member
Re: IDEA: Pull icon from exe and put on the containing folder
« Reply #11 on: February 11, 2021, 09:20 AM »
Hey thanks folks! 

The AHK one works like a carm.  I don't think the PowerShell one is working though(?)  I went with the "Send to" option.  It does open the PowerShell window, but nothing appears in the window, and it doesn't appear to do anything.  It's all good though.  I've got a bunch of different AHK scripts that I use, so there's no point in breaking with tradition.   :- }

Thanks again.

EDIT:  Also, extra points for 4wd, for writing code from his car...  Username checks out too!  LOL

4wd

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 5,506
    • View Profile
    • Donate to Member
Re: IDEA: Pull icon from exe and put on the containing folder
« Reply #12 on: February 11, 2021, 03:56 PM »
I don't think the PowerShell one is working though(?)  I went with the "Send to" option.  It does open the PowerShell window, but nothing appears in the window, and it doesn't appear to do anything.

Nothing appears in the window, it just writes the desktop.ini file into the directory.

Probably had to do what nod5 did and signal Windows to update.

Also, it seemed like IconResource was Vista only but maybe I read the MS docs wrong.
« Last Edit: February 11, 2021, 06:18 PM by 4wd »

publicdomain

  • Honorary Member
  • Joined in 2019
  • **
  • Posts: 260
  • Call me Vic!
    • View Profile
    • PublicDomainGift.com
    • Read more about this member.
    • Donate to Member
Re: IDEA: Pull icon from exe and put on the containing folder
« Reply #13 on: February 15, 2021, 03:33 PM »
Any takers?   :P

Hello dear kunkel, thanks for your valuable interaction via PM.

AppFolderIcon v0.1.0 is complete:

AppFolderIcon_v0-1-0.png



DCmembers download: https://www.dcmember...ppfoldericon-v0-1-0/

Github source code: https://github.com/p...domain/appfoldericon

AppFolderIcon thread: https://www.donation...ex.php?topic=51087.0

Enjoy! :Thmbsup:

Vic
♥♥♥ You may support this project by expressing your excitement in the form of a Donation using DonationCredits, via Paypal @ PayPal.me/victorvls or by becoming a Patron @ Patreon.com/publicdomain

Thanks & keep on rocking!
Email: publicdomainvicgmail.com

Coding: AppFolderIcon v0.2.0
--Victor
« Last Edit: February 15, 2021, 03:48 PM by publicdomain »

kunkel321

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 549
    • View Profile
    • Donate to Member
Re: IDEA: Pull icon from exe and put on the containing folder
« Reply #14 on: February 15, 2021, 05:17 PM »
Wow!  Very cool!  Thanks so much Vic!  I'll comment on the AppFolderIcon tread.  FYI to others:  Vic has made this app so that it intelligently determines which exe file is the most likely to contain the desired icon image -- Good stuff! 

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 40,541
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
Re: IDEA: Pull icon from exe and put on the containing folder
« Reply #15 on: February 16, 2021, 12:32 PM »
Just a reminder to folks to consider sending some donationcredits to people on the forum (click the gold coin under their name) who work on these coding snacks -- show them you appreciate what they are doing!

kunkel321

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 549
    • View Profile
    • Donate to Member
Re: IDEA: Pull icon from exe and put on the containing folder
« Reply #16 on: February 16, 2021, 05:05 PM »
Just a reminder to folks to consider sending some donationcredits to people on the forum (click the gold coin under their name) who work on these coding snacks -- show them you appreciate what they are doing!
Cool!  I never even noticed that those icons are all links! 

MilesAhead

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 7,649
    • View Profile
    • Miles Ahead Software
    • Donate to Member
Re: IDEA: Pull icon from exe and put on the containing folder
« Reply #17 on: February 17, 2021, 09:37 AM »

AppFolderIcon v0.1.0 is complete:

I have one of those cheapie W10 Laptops that tops out at .NET 4.0.  Unfortunately the Windows Update mechanism never worked correctly.  So I am kind of stuck with what I've got.  I wonder if there is something Win32 based that would have a similar function?  Maybe a VBasic scriptoid or some such? So far I have owned 2 laptops and they have both been Windows Update out of luck.  I am batting a thousand! I cannot even use restore points.  I image with Macrium Reflect Free to recover from disasters.   8)



kunkel321

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 549
    • View Profile
    • Donate to Member
Re: IDEA: Pull icon from exe and put on the containing folder
« Reply #18 on: February 17, 2021, 01:52 PM »
@MilesAhead, No doubt the AutoHotkey one that Nod5 made will work for you -- yes?

MilesAhead

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 7,649
    • View Profile
    • Miles Ahead Software
    • Donate to Member
Re: IDEA: Pull icon from exe and put on the containing folder
« Reply #19 on: February 18, 2021, 12:56 PM »
@MilesAhead, No doubt the AutoHotkey one that Nod5 made will work for you -- yes?

I forgot about that one.  Thanks.  I'll try it.   :Thmbsup:

Edit:  Works fine.   8)
« Last Edit: February 18, 2021, 01:08 PM by MilesAhead »