#173871 - 2007-02-13 09:30 AM
Efficient way to determine which .### class can open an app.?
|
MACE
Starting to like KiXtart
Registered: 2004-09-07
Posts: 150
Loc: Manchester UK
|
I am looking for an efficient means of determining which file extension classes will directly open an associated application. I want to create an index on logon so in a Intranet environment only the file & templates directly openable/shellable on the local machine are listed. No point listing a ###.XYZ file if it cant be opened by clicking on it! On investigating the classes on my pc, the ways of opening files are NUMEROUS and not simple to narrow down. I am experimenting with the following test script but there is probably a more direct method so seeking advice....
break on
Classes
get $a
Function CLASSES
;Machines CLASSES information.
GLOBAL $base
GLOBAL $output
GLOBAL $#
$base="HKEY_CLASSES_ROOT\"
$output="%USERPROFILE%\DESKTOP\%COMPUTERNAME%_CLASSES.txt"
$apps="%USERPROFILE%\DESKTOP\%COMPUTERNAME%_Apps.txt"
$#=","
IF exist ($output)
DEL $output /f
ENDIF
IF exist ($apps)
DEL $apps /f
ENDIF
DIM $nul
Open(2, $output,5)
Open(3, $apps,5)
If @error = 0
$null = ParseKeys() ; Run Query
Endif
Close (2)
CLose (3)
EndFunction
FUNCTION Parsekeys()
DIM $subkey
DIM $retvalue
$retvalue = ENUMKEY($base,$subkey)
WHILE @error=0
IF $retvalue <> "" and left($retvalue,1) = "."
$null = LogKeys($retvalue)
ENDIF
$subkey=$subkey+1
$retvalue = ENUMKEY($base,$subkey)
LOOP
ENDFUNCTION
FUNCTION LogKeys($keyname)
DIM $x
DIM $scounter
DIM $key
$key=$base+$keyname
$x = ENUMKEY($key,$scounter)
WHILE @error=0
ShellOpen($key,$Keyname,$x)
;This gives a nice list or .### file types currently registered.
WRITELINE (2, $keyname+@crlf)
$scounter=$scounter+1
$x = ENUMKEY($key,$scounter)
LOOP
ENDFUNCTION
FUNCTION ShellOpen($key,$keyname,$x)
;Need ideas what to look for to determine which .### run associated application!
SELECT
CASE $x = "OpenWithProgIDs"
OpenWithProgIDs($key,$Keyname,$x)
CASE $x = "shellex"
shellex($key,$Keyname,$x)
CASE $x = "OpenWithList"
OpenWithList($key,$Keyname,$x)
ENDSELECT
ENDFUNCTION
FUNCTION OpenWithProgIDs($key,$keyname,$x)
? $x
ENDFUNCTION
FUNCTION shellex($key,$keyname,$x)
? $x
ENDFUNCTION
FUNCTION OpenWithList($key,$keyname,$x)
? $X
ENDFUNCTION
|
|
Top
|
|
|
|
#173896 - 2007-02-13 11:41 PM
Re: Efficient way to determine which .### class can open an app.?
[Re: MACE]
|
MACE
Starting to like KiXtart
Registered: 2004-09-07
Posts: 150
Loc: Manchester UK
|
Narrowed it down to here so far, but one annoyiance, I can not retrieve the default values for some of the keys even though the keyexist = 1. What am I missing ?
break on
Classes
Function CLASSES
;Machines CLASSES information.
GLOBAL $base
GLOBAL $output
GLOBAL $#
$base="HKEY_CLASSES_ROOT\"
$output="%USERPROFILE%\DESKTOP\%COMPUTERNAME%_CLASSES.txt"
$apps="%USERPROFILE%\DESKTOP\%COMPUTERNAME%_Apps.txt"
$#=","
IF exist ($output)
DEL $output /f
ENDIF
IF exist ($apps)
DEL $apps /f
ENDIF
DIM $nul
Open(2, $output,5)
If @error = 0
$null = ParseKeys() ; Run Query
Endif
Close (2)
EndFunction
FUNCTION Parsekeys()
DIM $subkey
DIM $retvalue
$retvalue = ENUMKEY($base,$subkey)
WHILE @error=0
IF $retvalue <> "" and left($retvalue,1) = "."
$null = LogKeys($retvalue)
ENDIF
$subkey=$subkey+1
$retvalue = ENUMKEY($base,$subkey)
LOOP
ENDFUNCTION
FUNCTION LogKeys($ext)
DIM $ft, $key, $app, $sh,$x,$y
DIM $CT
$key=$base+$ext
$CT = 0
$ft = Enumkey($key,$CT)
WHILE @error=0
$app= enumkey($key+"\"+$ft,0)
SELECT
CASE $app = "ShellNew"
$x=$base+$ft+"\shell\Open\command"
If keyexist($x) = 1
$SH=enumvalue($x,0)
Endif
Case $ft = "OpenWithProgIDs"
$x= $key+"\"+$ft+"\"+$app
If keyexist($x) = 1
$y=$base+enumvalue($x,0)+"\shell\Open\command"
If keyexist($y)
$SH=enumvalue($y,0)
Endif
Endif
case $ft = "OpenWithList"
$SH=$APP
;case $ft = "shellex"
EndSelect
WriteLine(2,$ext+","+$sh+@CRLF)
$CT=$CT+1
$ft = EnumValue($key,$CT)
Loop
ENDFUNCTION
|
|
Top
|
|
|
|
#173897 - 2007-02-14 02:32 AM
Re: Efficient way to determine which .### class can open an app.?
[Re: MACE]
|
Shawn
Administrator
   
Registered: 1999-08-13
Posts: 8611
|
Neat, been playing with your function. To determine the "default" value suggest you just use the "ReadValue" function with a "null" parameter for the value - that returns the default value ...
FUNCTION LogKeys($ext)
DIM $ft, $key, $app, $sh,$x,$y
DIM $CT
$key = $base + $ext
$CT = 0
$x = $base + $ft + "\Shell\Open\Command"
If keyexist($x)
$sh = readvalue($x,"")
Else
$ft = ReadValue($key,"")
$x = $base + $ft + "\Shell\Open\Command"
If keyexist($x)
$SH=readvalue($x,"")
Endif
Endif
$= WriteLine(2,$ext+","+$sh+@CRLF)
EndFunction
|
|
Top
|
|
|
|
#173904 - 2007-02-14 01:45 PM
Re: Efficient way to determine which .### class can open an app.?
[Re: Shawn]
|
MACE
Starting to like KiXtart
Registered: 2004-09-07
Posts: 150
Loc: Manchester UK
|
Finished article: For my purposes I create two files, 'CLASSES' which is a list of the .### runnable suffixes , one per line. 'CLASSES+' which takes the form: .###,'Command line to run this suffix' I can envisage quite a number of uses...enjoy.
Classes
; Extract directly openable .### filename Classes from registry.
; File types which are not 'double clickable' will be excluded.
Function CLASSES
;Setup test file output
GLOBAL $base
DIM $Dest, $CLASSES, $CLASSES#
$base="HKEY_CLASSES_ROOT\"
$Dest="%USERPROFILE%\DESKTOP\"
$CLASSES=$Dest+"%COMPUTERNAME%_CLASSES.txt"
$CLASSES#=$Dest+"%COMPUTERNAME%_CLASSES+.txt"
IF exist ($CLASSES)
DEL $CLASSES /f
ENDIF
IF exist ($CLASSES#)
DEL $CLASSES# /f
ENDIF
DIM $nul
Open(2, $CLASSES,5)
Open(3, $CLASSES#,5)
If @error = 0
$null = ParseKeys() ; Run Query
Endif
Close (3)
Close (2)
EndFunction
;Extract the .### suffixes from the registry.
FUNCTION Parsekeys()
DIM $subkey
DIM $retvalue
$retvalue = ENUMKEY($base,$subkey)
WHILE @error=0
IF $retvalue <> "" and left($retvalue,1) = "."
$null = LogKeys($retvalue)
ENDIF
$subkey=$subkey+1
$retvalue = ENUMKEY($base,$subkey)
LOOP
ENDFUNCTION
;For each of the .### suffixes, determine which application runs it.
FUNCTION LogKeys($ext)
DIM $ft, $key, $app,$x,$y, $SH
$key=$base+$ext
$SH = readvalue($key+"\"+$ft,"")
If $SH = ""
$ft = Enumkey($key,0)
$app= readvalue($key+"\"+$ft,"")
SELECT
Case $ft = "OpenWithProgIDs"
$x= $key+"\"+$ft+"\"+$app
If keyexist($x) = 1
$y=$base+readvalue($x,"")+"\shell\Open\command"
If keyexist($y) = 1
StripIt(readvalue($y,""),$ext)
Endif
Endif
case $ft = "OpenWithList"
StripIt($APP,$ext)
EndSelect
Else
$x= $base+$SH+"\shell\Open\command"
If keyexist($x) = 1
StripIt(readvalue($x,""),$ext)
Endif
Endif
ENDFUNCTION
FUNCTION StripIt($S,$ext)
DIM $x, $y, $ct, $STR
;Strip out Quotes
For $x = 1 to len($S)
$y = substr($S,$x,1)
If $y <> '"' and $ct < 2
$STR=$STR+$y
Else
if $ct <2
$ct=$ct+1
Endif
Endif
next
;Strip off %1 to leave active string
SELECT
CASE right($Str,3) = " %L"
$Str = left($str,-3)
CASE right($Str,3) = " %1"
$Str = left($str,-3)
CASE right($Str,2) = "%1"
$Str = left($str,-2)
CASE right($Str,5) = " '%1'"
$Str = left($str,-5)
EndSelect
;Create Output File
If $Str <>""
$ = WriteLine(3,$ext+','+$str+@CRLF)
$ = WriteLine(2,$ext+@CRLF)
Endif
ENDFUNCTION
|
|
Top
|
|
|
|
Moderator: Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 1057 anonymous users online.
|
|
|