ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE.

DonationCoder.com Software > Post New Requests Here

IDEA: Pull icon from exe and put on the containing folder

<< < (3/4) > >>

Nod5:
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 ---#NoEnvSetWorkingDir %A_ScriptDir%#SingleInstance forceListLines, OffSetBatchLines, -1SetWinDelay, -1 ; SetExplorerFolderIcon.ahk; 2021-02-11; by Nod5; In Explorer press [F8] to set the focused file's first icon as parent folder icon; -----------------------------------; Default mode: ;   Select a file in Explorer and press [F8].;   To close the script right click its tray menu icon and Exit. ; Command line mode:;   Pass as parameter a HWND window handle to a specific Explorer window;   to act on that window's focused file and parent folder.; ; Optional: use this script from FARR (Find And Run Robot);   Create a FARR alias and use this as the result line (modify the path):;   Set Explorer parent folder icon | C:\some\folder\SetExplorerFolderIcon.ahk %LASTHWND%; ----------------------------------- ; if parameter is Explorer HWND then act on that window and exitif (vHwnd := A_Args[1]){  if WinExist("ahk_class CabinetWClass ahk_id " vHwnd)    GetFocusedFileSetIcon(vHwnd)  ExitApp}; else hotkey mode: create Explorer hotkey and await user actionelse{  Hotkey, IfWinActive, ahk_class CabinetWClass  Hotkey, F8, GetFocusedFileSetIcon}return GetFocusedFileSetIcon(vHwnd := ""){  vFile := ExplorerGetFocusedFilepath(vHwnd)  if FileExist(vFile)  {    SplitPath, vFile, , vFolder    SetFolderIcon(vFolder, vFile, 0)  }}  ; function: ExplorerGetFocusedFilepath(vHwnd := "")  v210211; return filepath of focused item in vHwnd (or active) Explorer windowExplorerGetFocusedFilepath(vHwnd := ""){  vHwnd := vHwnd ? vHwnd : WinActive("A")  if vHwnd and WinExist("ahk_class CabinetWClass ahk_id " vHwnd)    for Window in ComObjCreate("Shell.Application").Windows      if (Window.HWND = vHwnd)        ; https://docs.microsoft.com/en-us/windows/win32/shell/shellfolderview-focuseditem        return vFile := Window.Document.FocusedItem.Path}  ; function: SetFolderIcon() update Explorer folder icon in desktop.ini via SHGetSetFolderCustomSettings; by teadrinker 2017-10-09 https://www.autohotkey.com/boards/viewtopic.php?p=174984#p174984; https://docs.microsoft.com/en-us/windows/win32/api/shlobj_core/nf-shlobj_core-shgetsetfoldercustomsettings; https://docs.microsoft.com/en-us/windows/win32/api/shlobj_core/ns-shlobj_core-shfoldercustomsettingsSetFolderIcon(folderPath, iconPath, iconIndex)  {   static FCSM_ICONFILE := 0x10, FCS_FORCEWRITE := 0x2   if !A_IsUnicode  {      VarSetCapacity(WiconPath, StrPut(iconPath, "UTF-16")*2, 0)      StrPut(iconPath, &WiconPath, "UTF-16")   }   VarSetCapacity(SHFOLDERCUSTOMSETTINGS, size := 4*5 + A_PtrSize*10, 0)   NumPut(size, SHFOLDERCUSTOMSETTINGS)   NumPut(FCSM_ICONFILE, SHFOLDERCUSTOMSETTINGS, 4)   NumPut(A_IsUnicode ? &iconPath : &WiconPath, SHFOLDERCUSTOMSETTINGS, 4*2 + A_PtrSize*8)   NumPut(iconIndex, SHFOLDERCUSTOMSETTINGS, 4*2 + A_PtrSize*9 + 4)   DllCall("Shell32\SHGetSetFolderCustomSettings", Ptr, &SHFOLDERCUSTOMSETTINGS, WStr, folderPath, UInt, FCS_FORCEWRITE)} ; -----------------------------------; notes on desktop.ini files; -----------------------------------; https://docs.microsoft.com/en-us/windows/win32/shell/how-to-customize-folders-with-desktop-ini; "text file that allows you to specify how a file system folder is viewed."; See also https://hwiegman.home.xs4all.nl/desktopini.html ; Format:; -----; [.ShellClassInfo]; IconResource=C:\test\file.exe,0     ; <filepath, icon-index>; -----; To remove the custom folder icon delete desktop.ini ; If we just write the file then the new folder icon does not show immediately (must close/reopen Explorer); If we instead use SHGetSetFolderCustomSettings the new icon shows immediately.; SHGetSetFolderCustomSettings also hides the desktop.ini file.; https://docs.microsoft.com/en-us/windows/win32/api/shlobj_core/nf-shlobj_core-shgetsetfoldercustomsettings; https://docs.microsoft.com/en-us/windows/win32/api/shlobj_core/ns-shlobj_core-shfoldercustomsettings; AutoHotkey function: SetFolderIcon(); by Teadrinker 2017-10-09 https://www.autohotkey.com/boards/viewtopic.php?p=174984#p174984; -----------------------------------

kunkel321:
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:
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.-kunkel321 (February 11, 2021, 09:20 AM)
--- End quote ---

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.

publicdomain:
Any takers?   :P
-kunkel321 (February 09, 2021, 11:54 AM)
--- End quote ---

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

AppFolderIcon v0.1.0 is complete:





DCmembers download: https://www.dcmembers.com/publicdomainvic/download/appfoldericon-v0-1-0/

Github source code: https://github.com/publicdomain/appfoldericon

AppFolderIcon thread: https://www.donationcoder.com/forum/index.php?topic=51087.0

Enjoy! :Thmbsup:

Vic

kunkel321:
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! 

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version