;A snippet by Yochai Timmer (Yochai@Dorot.org.il)
;This is a little snippet that returns the default Icon set for the file type.
;Usage: $FileIcon(Filename.ext)
;Example: //echo -a $FileIcon(Test.txt)
;Returns: C:WINDOWSsystem32shell32.dll,-152
Updates:
The snippet can now evaluate %1 variable.
It will now find the correct files for files that are shown without a path in the registry (will search for them in system32).
And it will now return the default unasigned file icon if it can't find any other icon.
It will also return icon value 0 if no icon number was assigned (Windows doesn't require an icon number, cause default is 0, mIRC does require it.)
;A snippet by Yochai Timmer (Yochai@Dorot.org.il)
;This is a little snippet that returns the default Icon set for the file type.
;Usage: $FileIcon(Filename.ext)
;Example: //echo -a $FileIcon(Test.txt)
;Returns: C:\WINDOWS\system32\shell32.dll,-152
Alias FileIcon {
tokenize 32 $gettok($1-,-1,46) $1-
; Gets the extension.
var %root = $GetEnvStr(SystemRoot)
var %icon = $regread($+(HKEY_CLASSES_ROOT\.,$1,\DefaultIcon\))
; First of all, the snippet tries to read the default icon.
if (!%icon) var %icon = $regread($+(HKEY_CLASSES_ROOT\,$regread($+(HKEY_CLASSES_ROOT\.,$1,\)),\DefaultIcon\))
;If the file extension is associated with another program, it won't have a DefaulIcon key, so this will get the associated program.
if ($+(%,*,%) iswm $gettok(%icon,1,92) ) var %icon = $+($GetEnvStr($gettok($v2,1,37)),\,$gettok(%icon,2-,92))
;If the directory uses a windows variable, this should handle the variable and return a directory name.
if (!%icon) var %icon = $+(%root,\,system32\SHELL32.dll,$chr(44),0)
;If no Icon was found, this will call windows' default icon for unidentified file types.
var %file = $gettok(%icon,1,44)
if (%file = $+($chr(37),1)) {
if ($exists($2-)) var %icon = $+($2-,$chr(44),0)
else var %icon = $+(%root,\,system32\SHELL32.dll,$chr(44),2)
}
;Checks for %1 value (in .exe files, the deafault icon is their own.) and return the file's first icon (if file exists) or the icon for executables.
elseif ($exists($+(%root,\system32\,%file))) var %icon = $puttok(%icon,$+(%root,\system32\,%file),1,44)
;Some registry default icons just show the dll name, and expect windows to know to search in the system32 directory to see if it exists.
elseif (!$exists(%file)) var %icon = $+(%root,\,system32\SHELL32.dll,$chr(44),0)
;If the script can't file the file afterall just put the default unasigned file icon.
if ($numtok(%icon,44) = 1) var %icon = $addtok(%icon,0,44)
;If %icon contains an icon file with no icon number, then select the first icon by default. (Usually .ico file don't require an icon number in windows, but you need it in mIRC)
return %icon
}
Alias GetEnvStr {
.comopen env WScript.Shell
var %r = $com(env,ExpandEnvironmentStrings,3,bstr,$+(%,$1,%))
if (%r) %r = $com(env).result
.comclose env
return $iif(%r == $+(%,$1,%),$null,%r)
}
Alias -l Regread {
var %a = regread
.comopen regread WScript.Shell
if (!$comerr) {
var %a = $com(regread,RegRead,3,bstr,$1-)
var %a = $com(regread).result
.comclose regread
return %a
}
.comclose regread
}