Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

GrabIco (extract icon s)


  • Please log in to reply
4 replies to this topic
Kerry
  • Members
  • 144 posts
  • Last active: Sep 25 2006 07:33 PM
  • Joined: 20 Jul 2006
Really easy method to grab icons... you select the file and it sticks its ico in the current directory.

;
; AutoHotkey Version: 1.x
; Language:       English
; Platform:       Win9x/NT
; Author:         Kerry <[email protected]>
;
; Script Function:
;	Takes a programs icon and sticks it in the current folder.
;   Supports EXE, DLL, OCX, CPL, and more
;
; Please visit http://www.nirsoft.net/utils/iconsext.html for variations with iconsext.exe

#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.

FileInstall readme.txt, %A_ScriptDir%\readme.txt, 0
FileInstall iconsext.exe, %A_ScriptDir%\iconsext.exe, 0
FileInstall iconsext.chm, %A_ScriptDir%\iconsext.chm, 0

FileSelectFile, file, 1,,Please select a program with an .exe`, .ocx`, .dll` or .cpl extension, Program Files (*.exe; *.ocx; *.dll; *.cpl)
If file =
{
	DelFile("readme.txt")
	DelFile("iconsext.exe")
	DelFile("iconsext.chm")
	ExitApp
}

file := ShortPath(file)
dir := ShortPath(A_ScriptDir)
Run iconsext /save %file% %dir% -icons,, Hide
SplitPath file,,,, iFile
MsgBox The icon(s) have been created in %A_ScriptDir%

DelFile("readme.txt")
DelFile("iconsext.exe")
DelFile("iconsext.chm")

ShortPath(LongPath) 
{
	Loop, %LongPath%, 1
	Return A_LoopFileShortpath
}

DelFile(path)
{
	IfExist %path%
	{
		FileDelete %A_ScriptDir%\%path%
	}
}

It's required in the programs license to have all files be used if redistributed: http://www.nirsoft.n...ls/iconsext.zip

-Kerry

EDIT:

changed title to GrabIc (extract icon s) so that if someone searches the forum for "extract icon" it can be found (like I did).

SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005
Dear Kerry, :)

I suggest the following:

Replace the lines:

iFile := FileName(file) 
iFile := StripExt(ifile)

With the following line:

SplitPath, file, ,,,iFile

And remove the following two functions:

StripExt(file) ; Strips the extension off a file 
{ 
   fLength := StrLen(file) 
   fCount := fLength - 4 
   StringLeft name, file, %fCount% 
   Return %name% 
} 

FileName(path) ; Returns file name out of a path 
{ 
   pLength := StrLen(path) 
   StringGetPos pPos, path, \, R1 
   If ErrorLevel = 1 
   { 
      file = %path% 
   } Else 
   { 
      fToGet := pLength - 1 - pPos 
      StringRight, file, path, %fToGet% 
   } 
   Return %File% 
}


and that will save you many lines of code.

Regards, :)
kWo4Lk1.png

PhiLho
  • Moderators
  • 6850 posts
  • Last active: Jan 02 2012 10:09 PM
  • Joined: 27 Dec 2005
Good remark Goyyah.
Plus the StripExt function is obviously wrong, you can have shorter extensions (.c, .h, .vb, .js...) and much longer extensions (.html, .properties, etc.), not to mention compound extensions (but Windows is confused by them as well: .tar.gz, .user.js).
It is OK in the above context (probably only scanning .exe, .dll and similar) but since it looks like a generic function...
Posted Image vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")

SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005

StripExt function is obviously wrong, you can have shorter extensions (.c, .h, .vb, .js...) and much longer extensions (.html, .properties, etc.), not to mention compound extensions (but Windows is confused by them as well: .tar.gz, .user.js).


Very true .. ( I did not read the code in full! )
.. and also it needs mentioning here that FileSelectFile Command has Filter option with which Kerry can control which file extensions can be selected.

Regards, :)
kWo4Lk1.png

Kerry
  • Members
  • 144 posts
  • Last active: Sep 25 2006 07:33 PM
  • Joined: 20 Jul 2006
Hey, thanks for the corrections!

The code is updated, and I added in a little error code (such as if they click cancel) and some comments that should help. I couldn't find that the "other" apps are at the moment, so I just limited it to those four.

And PhiLho, you're totally right. I made that function in a quick need to get rid of a .exe (in another program) without thinking of other extensions

Thanks for the SplitPath I'm still pretty new to AutoHotKey (started thursday morning) so I'm lacking the knowledge of a lot of the functions... and so creating my own poorer quality ones :wink:.

-Kerry