home *** CD-ROM | disk | FTP | other *** search
Wrap
' ######################################################################## ' ' --==** bestimme_dateityp.vbs - Version 1.1 **==-- ' ' ein ADD-ON zum Programm PUTZI 4 WIN ' ' ------------------------------------------------------------------------ ' Autor: ' ~~~~~~ ' Axel Hahn * support@putzi4win.de.de ' http://www.putzi4win.de ' ------------------------------------------------------------------------ ' Zweck: ' ~~~~~~ ' Datei-Erweiterungen in der TYPES.DAT suchen ... ' Nach Eingabe eines Datei-Filters (auch mit Platzhalter) ' wird die Datei TYPES.DAT, die im Programm Putzi 4 Win als ' "Datenbank" von Dateitypen dient, durchsucht. ' Die Ausgabe erfolgt als Tabelle im Explorer-Fenster. ' ------------------------------------------------------------------------ ' Installation: ' ~~~~~~~~~~~~~ ' kopieren Sie diese Datei in den Ordner des Programmes ' Putzi4Win und starten Sie es aus diesem Ordner. ' ------------------------------------------------------------------------ ' History: ' ~~~~~~~~ ' 2000-10-29 V1.0 erste Version von Axel Hahn ' 2001-06-16 V1.1 Informationenen im Ausgabefenster erweitert: ' * Rubriken der Dateitypen ' * Zus.fassung der Stati aller Dateitypen ' dieses VBScript geh÷rt nun zum Programmumfang ' ######################################################################## Option explicit ' ========================================================= ' CONFIG ' ========================================================= ' --- Variablen --- Dim REGINFOS, ALLINFOS, dummy, Html_Inithead, Html_HLP_Eingabe, Html_HLP_Ausgabe ' --- Objekte --- Dim fso, regEx, ie4, WSHShell ' --- Konstanten --- const ForReading = 1 const infofile= "TYPES.DAT" const default_ext = "*.TMP" const regfile = "HKCR_export.reg" const regtmpfile = "HKCR_export.tmp" const str_about = "bestimme_dateityp.vbs V1.1<BR>© 2000-2001 Axel Hahn" ' ========================================================= ' MAIN ' ========================================================= call Init_Objects() ' to do: ' call exportFromRegistry() call ask_user() dummy=quit_now(0,"") ' ######################################################################## ' ' SUBS ' ' ######################################################################## ' ========================================================= ' create all objects required in this script - then the ' script terminates in the first function call, if someone ' has an older version of WSH or VBScript ' ========================================================= sub Init_Objects() Dim err_oldversion, all_errors err_oldversion= _ "Anmerkung:" _ & vbcrlf & "Evtl. liegt dies auch daran, dass Sie eine Σltere Version" _ & vbcrlf & "des Windows Scripting Host (WSH) oder der VBScript-Engine" _ & vbcrlf & "verwenden." _ & vbcrlf & vbcrlf & "Ihre Engine:" _ & vbcrlf & "Name: " & Wscript.Name & " (Version " & Wscript.Version & ")"_ & vbcrlf & "Script-Engine: " & CStr(ScriptEngine()) _ & " (Version " & CStr(ScriptEngineMajorVersion()) _ & "." & CStr(ScriptEngineMinorVersion()) _ & "; Built " & CStr(ScriptEngineBuildVersion()) & ")" all_errors="" On Error Resume Next ' ------------------------------------------------------- ' object: FileSystemObject ' ------------------------------------------------------- Set fso = CreateObject("Scripting.FileSystemObject") if Err.Number>0 then all_errors=all_errors & _ "* Objekt kann nicht erstellt werden: Scripting.FileSystemObject" & _ vbcrlf & _ " Fehlercode # " & CStr(Err.Number) & ": " & Err.Description & _ vbcrlf & vbcrlf Err.Clear end if ' ------------------------------------------------------- ' object: regular expressions ' ------------------------------------------------------- Set regEx = New RegExp if Err.Number>0 then all_errors=all_errors & _ "* Objekt kann nicht erstellt werden: RegExp" & _ vbcrlf & _ " Fehlercode # " & CStr(Err.Number) & ": " & Err.Description & _ vbcrlf & vbcrlf Err.Clear end if ' ------------------------------------------------------- ' object: Internet Explorer ' ------------------------------------------------------- set ie4 = WScript.CreateObject("InternetExplorer.Application", "event_") if (err.number > 0) then all_errors=all_errors & _ "* Objekt kann nicht erstellt werden: InternetExplorer.Application" & _ vbcrlf & _ " Fehlercode # " & CStr(Err.Number) & ": " & Err.Description & _ vbcrlf & vbcrlf Err.Clear else ie4.width = 600 ie4.height = 400 ie4.top = 5 ie4.left = 5 ie4.Toolbar = false ie4.Statusbar = false ie4.navigate _ ("JavaScript:'<title>PUTZI 4 WIN - Ausgabe</title><body " _ & "scroll=yes></body>'") do loop while ie4.ReadyState<>4 end if ' ------------------------------------------------------- ' object: WScript Shell ' ------------------------------------------------------- set WSHShell=WScript.CreateObject("WScript.Shell") if (err.number > 0) then all_errors=all_errors & _ "* Objekt kann nicht erstellt werden: WScript.Shell" & _ vbcrlf & _ " Fehlercode # " & CStr(Err.Number) & ": " & Err.Description & _ vbcrlf & vbcrlf Err.Clear end if ' ------------------------------------------------------- ' check errors ' ------------------------------------------------------- if all_errors>"" then dummy=quit_now(1,all_errors & err_oldversion) end if ' ------------------------------------------------------- ' eigentlich Konstanten: Hilfe-Strings ' ------------------------------------------------------- Html_Inithead= "<TABLE WIDTH=100% bgcolor=#D0C0FF><TR><TD>" & _ "<H2>Initialisierung</H2></TD>" & _ "</TD><TD ALIGN=RIGHT VALIGN=TOP>" & str_about & "</TD></TR></TABLE><BR>" & _ "<B>Status:</B><BR>" Html_HLP_Eingabe= "<TABLE WIDTH=100% bgcolor=#D0C0FF><TR><TD>" & _ "<H2>Hilfe zur Eingabe</H2></TD>" & _ "</TD><TD ALIGN=RIGHT VALIGN=TOP>" & str_about & "</TD></TR></TABLE><BR>" & _ "<B>Was ist das eigentlich hier?</B><BR>" & _ "Geben Sie einen beliebigen Dateifilter ein - es listet Ihnen daraufhin die passenden Dateitypen auf. Die zurⁿckgelieferten Informationen stammen aus der ASCII-Datei TYPES.DAT im Programmordner des Programmes PUTZI 4 WIN.<BR><BR>" & _ "<B>Syntax fⁿr Dateifilter</B><BR>" & _ "GrundsΣtzlich k÷nnen beliebige Dateifilter nach der Syntax <BR>" & _ "<B>[Dateiname].[Dateierweiterung]</B><BR> eingegeben werden. Auf Gross- " & _ "und Kleinschreibung braucht (wie unter DOS und Windows ⁿblich) nicht " & _ "geachtet zu werden. Auch die Verwendung von Platzhaltern ist " & _ "m÷glich:" & _ "<BLOCKQUOTE>" & _ "<B>*</B> steht fⁿr mehrere beliebige oder kein Zeichen<BR>" & _ "<B>?</B> steht fⁿr genau 1 Zeichen (*.B?K passt z.B. auf *.BAK, *.BNK, ...)" & _ "</BLOCKQUOTE>" & _ "Da in der Datei TYPES.DAT vorwiegend die verschiedensten" & _ "Dateierweiterungen enthalten sind, ist die Verwendung des" & _ "Platzhalters * als Dateiname am sinnvollsten." & _ "" & _ "" Html_HLP_Ausgabe= "<TABLE WIDTH=100% bgcolor=#D0C0FF><TR><TD>" & _ "<H2>Hilfe zum Ausgabefenster</H2></TD>" & _ "</TD><TD ALIGN=RIGHT VALIGN=TOP>" & str_about & "</TD></TR></TABLE><BR>" & _ "<B>Was ist das eigentlich hier?</B><BR>" & _ "" ' ------------------------------------------------------- ' get fileinfos of TYPES.DAT ' ------------------------------------------------------- ie4.visible = true ie4.document.body.innerHTML = Html_Inithead & "Lese " & infofile ALLINFOS=readCompleteFile(infofile) ' MsgBox(ALLINFOS) if Len(ALLINFOS)=0 then dummy=quit_now(2,"Die Konfig-Datei <" & infofile & "> ist leer (???).") end if end sub ' ========================================================= ' export ' ========================================================= sub exportFromRegistry() Dim cmd ie4.document.body.innerHTML = Html_Inithead & "Exportiere HKEY_CLASSES_ROOT aus der Registry..." ' step 1: export registry Key HKEY_CLASSES_ROOT RUN("regedit /E " & regfile & " HKEY_CLASSES_ROOT") ' step 2: grep lines with fileextensions from output of step 1 cmd = "%COMSPEC% /c find ""HKEY_CLASSES_ROOT\."" " & regfile & " | sort > " & regtmpfile ie4.document.body.innerHTML = Html_Inithead & "ermittle registrierte Dateitypen..." ' MsgBox cmd RUN(cmd) ie4.document.body.innerHTML = Html_Inithead & "lese Textfile " & regtmpfile & "..." REGINFOS = readCompleteFile(regtmpfile) ' MsgBox(REGINFOS) end sub ' ========================================================= ' main function: ask user and create result-list ' ========================================================= sub ask_user() Dim userinput, i, count, char, char1, regpattern, result, LINE, ext, del, info Dim HtmlHead, HtmlOut, found_dot, tcolor, del_OK, del_warn, del_neutral Dim regtype, regcmd, regmime, count_reg ie4.document.body.innerHTML = Html_HLP_Eingabe userinput=default_ext do userinput=UCase(InputBox( _ "Platzhalter sind m÷glich:" & vbcrlf & _ "? = 1 Zeichen; * = beliebig viele Zeichen" & vbcrlf & _ "Beispiel: " & vbcrlf &_ "*.B?K passt auf *.BAK, *.BNK, ..." & vbcrlf & vbcrlf &_ ":h oder :? zeigen eine Hilfe." & vbcrlf, _ "Putzi 4 Win - Dateifilter eingeben" , _ userinput _ )) select case userinput case "" ' do noting case ":H", ":?" ie4.visible = true ie4.document.body.innerHTML = Html_HLP_Eingabe userinput=default_ext case else if (Mid(userinput,1,1)=".") then userinput="*" &userinput end if ' ----------------------------------------------------- ' built pattern for regexp object ' ----------------------------------------------------- regpattern="" i=0 found_dot=false Do i=i+1 char=Mid(userinput,i,1) select case char case "." found_dot=true char1="\." case "?" char1="." case "*" char1=".*" case "A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z" char1=char case "0","1","2","3","4","5","6","7","8","9" char1=char case else char1="\" & char ' case else char1=char end select regpattern = regpattern + char1 Loop While i < Len(userinput) ' regpattern2 ' MsgBox(regpattern2) ' \n fuer Zeilenumbruch regpattern= "\n" & regpattern & "\ .*" ' ----------------------------------------------------- ' search for fileinfos ' ----------------------------------------------------- HtmlHead= "<TABLE WIDTH=100% bgcolor=#D0C0FF><TR><TD>" HtmlHead= HtmlHead & "<H2>Ausgabe zu Dateifilter <" & userinput & "></H2></TD>" HtmlHead= HtmlHead & "</TD><TD ALIGN=RIGHT VALIGN=TOP>" & str_about & "</TD></TR></TABLE><BR>" if (found_dot=false) then HtmlHead= HtmlHead & "HINWEIS:<BR>Im angegebenen Dateifilter ist kein Punkt enthalten. Es können dadurch falsche Ergebnisse zurückgeliefert werden.<BR><BR>" end if ie4.visible = true ie4.document.body.innerHTML = HtmlHead & "STATUS:<BR><B>* Suche läuft...</B><BR>* Stelle Ergebnisse zusammmen..." result="" ' MsgBox("regpattern=" & regpattern & vbcrlf & "Ergebnis:" & RegExpTest(regpattern, ALLINFOS)) result=RegExpTest(regpattern, ALLINFOS) ie4.document.body.innerHTML = HtmlHead & "STATUS:<BR>* Suche läuft...<BR><B>* Stelle Ergebnisse zusammmen...</B>" count=0 del_OK=0 del_warn=0 del_neutral=0 count_reg=0 ' MsgBox(result) if (result="") then HtmlOut= "<H2>kein Treffer :-(</H2>" else HtmlOut="<TABLE WIDTH=100% CELLSPACING=0>" & _ "<TR><TD bgcolor=#D0C0FF><B>Dateityp</B></TD><TD bgcolor=#D0C0FF ALIGN=CENTER><B>temp?</B></TD><TD bgcolor=#D0C0FF><B>Beschreibung</B></TD></TR>" For Each LINE In Split(result, vbcrlf) if (LINE>"") then ext=RTrim(Mid(LINE,1,16)) if (InStr(ext, ".")=0) then ext = ext & "*.*" end if del=Mid(LINE,17,1) info=Mid(LINE,18) ' MsgBox("ext = " & ext & " | del = " & del) if (RegExpTest(regpattern, ext & " ")>"") then count=count+1 if ((count/2) = (count\2)) then tcolor="#E0E0E0" else tcolor="#F0F0F0" end if HtmlOut= HtmlOut & "<TR><TD VALIGN=TOP bgcolor=" & tcolor & "><B>" & ext & "</B></TD>" if (del="+") then HtmlOut= HtmlOut & "<TD bgcolor=90E090 align=center VALIGN=TOP>ja</TD>" del_OK=del_OK + 1 elseif (del="-") then HtmlOut= HtmlOut & "<TD bgcolor=F0c0c0 align=center VALIGN=TOP>!!!</TD>" del_warn=del_warn + 1 else HtmlOut = HtmlOut & "<TD align=center VALIGN=TOP bgcolor=" & tcolor & ">?</TD>" del_neutral=del_neutral + 1 end if HtmlOut= HtmlOut & "<TD bgcolor=" & tcolor & ">" & info & "<BR>" ext=Mid(ext,2,16) regtype=RegKey_value("HKEY_CLASSES_ROOT\" & ext & "\") if NOT(regtype=false) then count_reg = count_reg + 1 regmime=RegKey_value("HKEY_CLASSES_ROOT\" & ext & "\Content Type") regcmd=RegKey_value("HKEY_CLASSES_ROOT\" & ext & "\shell\open\command\") if (regcmd=false) then regcmd=RegKey_value("HKEY_CLASSES_ROOT\" & regtype & "\shell\open\command\") if (regtype=false) then regmime="- kein Eintrag -" if (regmime=false) then regmime="- kein Eintrag -" if (regcmd=false) then regcmd="- kein Eintrag -" HtmlOut= HtmlOut & "<FONT COLOR=#A04040>" & _ "<B>!!! registrierter Dateityp !!!</B><BR>" & _ "Typ: " & regtype & "<BR>" & _ "MIME: " & regmime & "<BR>" & _ "╓ffnen: " & regcmd & "<BR>" & _ "</FONT>" end if HtmlOut= HtmlOut & "</TD></TR>" end if end if Next HtmlHead = HtmlHead & "<TABLE BORDER=0 BGCOLOR=#D0C0FF WIDTH=10%><TR><TD><B>Zusammenfassung:</B></TD></TR></TABLE>" & _ "<TABLE WIDTH=100% BORDER=0 BGCOLOR=#F0F0F0><TR><TD VALIGN=TOP ALIGN=RIGHT WIDTH=10%><B>" & infofile & ":</B></TD>" & _ "<TD ALIGN=RIGHT WIDTH=30%>Treffer in dieser Datei:</TD><TD><B>" & count & "</B></TD></TR>" & _ "<TR><TD></TD><TD VALIGN=TOP ALIGN=RIGHT>gefundene Stati:</TD><TD>" if (del_OK>0) then HtmlHead=HtmlHead & "<FONT color=#207020>" & del_OK & " x bedenkenlos l÷schbar</FONT><BR>" if (del_neutral>0) then HtmlHead=HtmlHead & "<FONT color=#A0A020>" & del_neutral & " x neutral</FONT><BR>" if (del_warn>0) then HtmlHead=HtmlHead & "<FONT color=#A02020>" & del_warn & " x !!! Warnungen !!!</FONT><BR>" if (count_reg>0) then HtmlHead=HtmlHead & "</TR><TR><TD ALIGN=RIGHT><BR><B>Registry:</B></TD><TD COLSPAN=2><FONT color=#A02020><BR>" & count_reg & " x registrierte Dateitypen gefunden !!!</FONT><BR>" HtmlHead = HtmlHead & "</TD></TR></TABLE><BR>" HtmlOut = HtmlOut & "</TABLE>" end if ' ----------------------------------------------------- ' search in registry (not supported yet) ' ----------------------------------------------------- ' For Each LINE In Split(REGINFOS, vbcrlf) ' if (LINE>"") then ' MsgBox LINE ' result=RegExpTest("\.bat", LINE) ' if (result>"") then ' MsgBox result ' end if ' end if ' next ' ----------------------------------------------------- ' show results ' ----------------------------------------------------- ie4.document.body.innerHTML = HtmlHead & HtmlOut end select loop until (userinput="") end sub ' ========================================================= ' free all objects and quit ' ========================================================= function quit_now(RetCode, strmessage) On Error Resume Next REGINFOS = "" ALLINFOS = "" WScript.Disconnect fso set fso=nothing WScript.Disconnect regEx set regEx=nothing ie4.Quit WScript.Disconnect ie4 set ie4=nothing WScript.Disconnect WSHShell set WSHShell=nothing if Len(strmessage)>0 then MsgBox strmessage end if ' dummy=MsgBox(RetCode,strmessage) WScript.Quit RetCode end function ' ######################################################################## ' ========================================================= ' read complete file ' IN: filename of configfile ' OUT: string with text of configfile ' ========================================================= function readCompleteFile(filename) dim result, Line, filehandle, section On Error Resume next section="" if fso.FileExists(filename) then Set filehandle = fso.OpenTextFile(filename, ForReading, False) if fso.GetFile(filename).size>0 then Do Line=filehandle.ReadLine if InStr(1, Line, ">>> ") then section="<B>" & Mid(Line,5,1000) & "</B><BR>" end if ' MsgBox(filename & " | Zeile = " & Line) if (NOT(Mid(Line,1,1)="|") _ and NOT(Mid(Line,1,3)=">>>")) then result=result & Mid(Line,1,17) & section & Mid(Line,18,1000) & vbCrLF ' result=result & Line end if Loop until (filehandle.AtEndOfStream) else Msgbox_result=MsgBox("Dateigroesse von <" & filename & "> ist " &fso.GetFile(filename).size& " Bytes!!!") end if filehandle.Close else dummy=quit_now(3, "Die Datei <" & filename & "> wurde nicht gefunden!" & vbcrlf & vbcrlf & _ "Bitte kopieren Sie das Skript <" & wscript.scriptname & "> in den" & vbcrlf & _ "Ordner des Programmes PUTZI 4 WIN und starten Sie es dort erneut." ) end if ' MsgBox(result) readCompleteFile=result end function ' ========================================================= ' test regexp ' ========================================================= Function RegExpTest(patrn, strng) Dim Match, Matches, RetStr ' MsgBox("regexp-Aufruf:" & patrn & " | " & strng) regEx.Pattern = patrn ' Set pattern. regEx.IgnoreCase = True ' Set case insensitivity. regEx.Global = True ' Set global applicability. Set Matches = regEx.Execute(strng) ' Execute search. For Each Match in Matches ' Iterate Matches collection. RetStr = RetStr & Match.Value & vbcrlf ' RetStr = RetStr & "Match found at position " ' RetStr = RetStr & Match.FirstIndex & ". Match Value is '" ' RetStr = RetStr & Match.Value & "'." & vbCRLF Next ' MsgBox("RetStr = " & RetStr) RegExpTest = RetStr End Function ' ========================================================= ' capture close event of MSIE window ' ========================================================= sub event_onQuit dummy=quit_now(8,"Sie haben das Fenster des MS Internet Explorer" & vbcrlf & _ "geschlossen. Das VBSkript wird daher ebenfalls beendet.") end sub ' ========================================================= ' read value of registry key ' ========================================================= function RegKey_value(regkey) dim wert On Error Resume Next wert=WSHShell.RegRead(regkey) if (Err.Number>0) or (wert=vbempty) then wert=false end if RegKey_value=wert end function ' ========================================================= ' execute a program ' IN : 1 = command-string ' OUT: returncode of execution ' ========================================================= ' this function is required for later impletations. ' it is not in use at th moment. function RUN(cmdstr) Dim result On Error Resume Next result = WSHShell.Run(cmdstr,0,true) if result>0 then MsgBox("Fehler bei Ausfⁿhren von <" & cmdstr & ">!!!") WScript.Quit result end if RUN=result end function ' ======================================================================== ' EOF ## info@axel-hahn.de | support@putzi4win.de ' ========================================================================