#14260 - 2001-11-14 03:49 PM
Re: Find executables
|
Kdyer
KiX Supporter
   
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
|
CO,You are probably going to want to do something like - code:
BREAK ON CLS ? "Looking at files... Please Wait." $FileName = Dir("%windir%\system32\*") While $FileName <> "" and @ERROR = 0 ? $FileName $CompanyName = GETFILEVERSION ($FileName,"CompanyName") $FileVersion = GETFILEVERSION ($FileName,"FileVersion") IF $CompanyName <> "" ;? $FileName ;? $CompanyName ;? $FileVersion $result=setconsole('show') $LogFile="C:\filelogw.TXT" $LogData = $FileName + Chr(9) + $FileVersion + Chr(9) + $CompanyName + Chr(13) + Chr(10) $result=0 $n=0 $result=Open(1, $LogFile, 5) If $result<>0 $result=WriteLine(1, $LogData) $result=Close(1) Endif $n=$n+1 ENDIF $FileName = Dir("") Loop CLS ? "Thanks, we are now done." Sleep 2
If you want to Enumerate all of the Directories on your drive, look at the example provided by Ruud called - ENUMDIR.KIX provided in the KIXTART Archive. HTH, - Kent
|
|
Top
|
|
|
|
#14263 - 2001-11-15 11:29 AM
Re: Find executables
|
Co
MM club member
 
Registered: 2000-11-20
Posts: 1342
Loc: NL
|
|
|
Top
|
|
|
|
#14264 - 2001-11-15 03:35 PM
Re: Find executables
|
Co
MM club member
 
Registered: 2000-11-20
Posts: 1342
Loc: NL
|
I'm almost there.... I've used your script and it looks very good BREAK ON CLS ? "Looking at files... Please Wait." $FileName = Dir("%windir%\system32\*.exe") While $FileName <> "" and @ERROR = 0 ? $FileName $CompanyName = GETFILEVERSION ($FileName,"CompanyName") $FileVersion = GETFILEVERSION ($FileName,"FileVersion") $FileDescription = GETFILEVERSION ($Filename,"FileDescription") $ProductName = GETFILEVERSION ($Filename,"ProductName") IF $CompanyName <> "" ;? $FileName ;? $CompanyName ;? $FileVersion $result=setconsole('show') $LogFile="e:\filelogw.TXT" $LogData = $FileName + Chr(9) + $FileDescription + Chr(9) + $FileVersion + Chr(9) + $CompanyName+ Chr(9) + $ProductName + Chr(13) + Chr(10) $result=0 $n=0 $result=Open(1, $LogFile, 5) If $result<>0 $result=WriteLine(1, $LogData) $result=Close(1) Endif $n=$n+1 ENDIF $FileName = Dir("") Loop CLS ? "Thanks, we are now done." Sleep 2 result:
ARP.EXE TCP/IP Arp Command 4.00 Microsoft Corporation Microsoft(R) Windows NT(TM) Operating System ATSVC.EXE Net Schedule Service App 4.00 Microsoft Corporation Microsoft(R) Windows NT(TM) Operating System AUTOCHK.EXE Auto Check Utility 4.00 Microsoft Corporation Microsoft(R) Windows NT(TM) Operating System With this script i can find files in a directory but not in its subdirectories. If you want to find files in subdirectories you need to use Shell "%comspec% /c dir /s /b *.exe > $tmpfile" I've tried to read the textfile with a readline commando and a while loop but it will not work AARGGh I hope someone can help me with this last part... Co 
_________________________
Co
|
|
Top
|
|
|
|
#14266 - 2001-11-15 05:15 PM
Re: Find executables
|
Co
MM club member
 
Registered: 2000-11-20
Posts: 1342
Loc: NL
|
GRRR , I'm going home!!It doesn't work. This is one of my last creations: BREAK ON $filename = "*.exe" $startdir = "d:\users\" $tmpfile = "d:\log\files.txt" CD "$startdir" SHELL "%comspec% /c dir /s /b $filename > $tmpfile" ; sleep 20 $nul = open(1,$tmpfile,2) $filename = readline(1) while @error = 0 ? $filename $CompanyName = GETFILEVERSION ($FileName,"CompanyName") $FileVersion = GETFILEVERSION ($FileName,"FileVersion") $FileDescription = GETFILEVERSION ($Filename,"FileDescription") $ProductName = GETFILEVERSION ($Filename,"ProductName") IF $CompanyName <> "" $result=setconsole('show') $LogFile="e:\filelogw.TXT" $LogData = $FileName + Chr(9) + $FileDescription + Chr(9) + $FileVersion + Chr(9) + $CompanyName+ Chr(9) + $ProductName + Chr(13) + Chr(10) $result=0 $n=0 $result=Open(1, $LogFile, 5) If $result<>0 $result=WriteLine(1, $LogData) $result=Close(1) Endif $n=$n+1 ENDIF ;$FileName = Dir("") $filename = readline(1) ? $filename Loop CLS I've used a do..until loop and it gives the same results. Co 
_________________________
Co
|
|
Top
|
|
|
|
#14267 - 2001-11-16 02:07 AM
Re: Find executables
|
MCA
KiX Supporter
   
Registered: 2000-04-28
Posts: 5152
Loc: Netherlands, EU
|
Dear,First we reformat your script.
code:
BREAK ON $filename = "*.exe" $startdir = "d:\users\" $tmpfile = "d:\log\files.txt" CD "$startdir" SHELL "%comspec% /c dir /s /b $filename > $tmpfile" ; sleep 20 $nul = open(1,$tmpfile,2) $filename = readline(1) WHILE @error = 0 ? $filename $companyname = GETFILEVERSION ($filename,"CompanyName") $fileversion = GETFILEVERSION ($filename,"FileVersion") $filedescription = GETFILEVERSION ($filename,"FileDescription") $productname = GETFILEVERSION ($filename,"ProductName") IF $companyname <> "" $result=setconsole('show') $logfile="e:\filelogw.TXT" $logdata = $filename + Chr(9) + $filedescription + Chr(9) + $fileversion + Chr(9) + $companyname+ Chr(9) + $productname + Chr(13) + Chr(10) $result=0 $n=0 $result=Open(1, $logfile, 5) IF $result<>0 $result=WriteLine(1, $logdata) $result=Close(1) ENDIF $n=$n+1 ENDIF ;$FileName = Dir("") $filename = readline(1) ? $filename LOOP CLS
We find your problem with the WHILE/LOOP structure. You read the information from unit 1 and when you find a record you want to write to same unit 1. This is of course not possible, but only the Close(1) will be executed correctly and the next ReadLine(1) call will return an error. We have also reformat your script a little bit. Some remarks:
- put your variables at the big of your script. so we move the variable $logfile
to the big of your script.
- you don't need the cd command first. You can specify your $startdir
during the shell command.
- we quot your DIR specification. By the usage of longfilename it will not create
an error.
- We are only entry the WHILE/LOOP structure, when the file has been
opened without errors.
- the $result=0 isn't necessary.
- we have remove the $n statements. They are unused.
- we change $result to $nul when you don't really use it.
It may give you an idea to improve your script.Our version:
code:
CLS BREAK ON $filename = "*.exe" $startdir = "d:\users\" $tmpfile = "d:\log\files.txt" $logfile = "e:\filelogw.txt" $startdir = "c:\windows\" ; - our specification - $tmpfile = "c:\temp\files.txt" ; - our specification - $logfile = "c:\temp\filelogw.txt" ; - our specification - ; ? "Check "+$startdir+$filename ? "Logfile "+$logfile ; SHELL '%comspec% /c dir "$startdir$filename" /s /b >$tmpfile ' ; IF Open(1,$tmpfile,2) $filename = ReadLine(1) WHILE (@error = 0) ? $filename $companyname=GetFileVersion($filename,"CompanyName") $fileversion=GetFileVersion($filename,"FileVersion") $filedescription=GetFileVersion($filename,"FileDescription") $productname=GetFileVersion($filename,"ProductName") IF ($companyname <> "") $logdata=$filename+Chr(9)+$filedescription+Chr(9)+$fileversion+Chr(9)+$companyname+Chr(9)+$productname+Chr(13)+Chr(10) IF Open(2, $logfile, 5) $nul=WriteLine(2, $logdata) $nul=Close(2) ENDIF ENDIF $filename=ReadLine(1) LOOP $nul=Close(1) ENDIF ? "completed"
A piece of output "c:\temp\files.txt":
code:
c:\windows\accstat.exe c:\windows\arp.exe c:\windows\bcuninstall.exe c:\windows\calc.exe c:\windows\cd32.exe .... c:\windows\system\dcom95\oldole\dllhost.exe c:\windows\system\dcom95\oldole\rpcss.exe c:\windows\system\dcom95\oldole\uninstal.exe
The result file can be "c:\temp\filelogw.txt":
code:
c:\windows\arp.exe TCP/IP Arp Command 3.51 Microsoft Corporation Microsoft® Windows NT(TM) Operating System c:\windows\cdplayer.exe CD Player accessory 4.00.950 Microsoft Corporation Microsoft® Windows® Operating System c:\windows\clspack.exe Class Package Export Tool 5.00.3167 Microsoft Corporation Microsoft(R) Windows (R) Operating System c:\windows\defrag.exe Microsoft Disk Defragmenter 4.00.1111 Microsoft Corporation Microsoft® Windows® Operating System c:\windows\directcc.exe Direct Cable Connection application 4.00.1111 Microsoft Corporation Microsoft® Windows® Operating System .... c:\windows\system\dcom95\oldole\uninstal.exe Install DCOM for Windows 95 4.71.3116 Microsoft Corporation Microsoft(R) Windows NT(TM) Operating System
greetings.
|
|
Top
|
|
|
|
#14268 - 2001-11-16 03:11 AM
Re: Find executables
|
Bryce
KiX Supporter
   
Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
|
CO, what version of kix are you using?3.63 or 4.0? if you are using 4.0, I just created a UDF that might be of some help to you. http://kixtart.org/cgi-bin/ultimatebb.cgi?ubb=get_topic&f=2&t=002510 and example on how to use it. code:
;this load's the UDF call "dirplus.kix" ;this gets all .exe files in the $windir%\system32 tree $dir = dirplus("%windir%\system32",".exe",1)
for each $file in $dir ? $file next
Bryce
|
|
Top
|
|
|
|
#14269 - 2001-11-16 11:56 AM
Re: Find executables
|
Co
MM club member
 
Registered: 2000-11-20
Posts: 1342
Loc: NL
|
MCA,When i used your script it doesn't work the first time. The tempfile was created but not the final file. In debug mode i noticed that after the command if open(1,$tmpfile,2) the script makes a jump to ? "completed" I've made some changes and now it works: Thanks everyone how has helped me !!! Here it is the final script: CLS BREAK ON $file = "*.exe" $startdir = "c:\windows\" $tmpfile = "d:\log\temp.txt" $logfile = "d:\log\files.txt" ; ? "Check "+$startdir+$file ? "Logfile "+$logfile ; SHELL '%comspec% /c dir "$startdir$file" /s /b >$tmpfile' ; IF Open(1,$tmpfile,2) = 0 $filename = ReadLine(1) ; ? "Line read: [" + $filename + "]" ; WHILE @error = 0 ? $filename $companyname=GetFileVersion($filename,"CompanyName") $fileversion=GetFileVersion($filename,"FileVersion") $filedescription=GetFileVersion($filename,"FileDescription") $productname=GetFileVersion($filename,"ProductName") IF ($companyname <> "") $logdata=$filename+Chr(9)+$filedescription+Chr(9)+$fileversion+Chr(9)+$companyname+Chr(9)+$productname+Chr(13)+Chr(10) IF Open(2, $logfile, 5) $nul=WriteLine(2, $logdata) $nul=Close(2) ENDIF ENDIF $filename=ReadLine(1) LOOP $nul=Close(1) ENDIF del $tmpfile ? "completed" exit (A bulletin board like this is not only good for you KIX knowhow but also for your English, Pfff ) Co
_________________________
Co
|
|
Top
|
|
|
|
#14271 - 2002-11-22 10:29 PM
Re: Find executables
|
CalderX
Fresh Scripter
Registered: 2002-04-24
Posts: 6
Loc: Boden north of Sweden
|
Hey!
I have tested the script and it works fine, but it seems to miss some exe-files when I run it. is it becuse some files don´t have certain data within it, for example "companyname" or it is something else? When I test it I´l put some exe-files in a directory and run it, the temp.txt contain all files but the files.txt contains less...? Am I missing something?
Thanks i advance!
Calle (excuse my spelling)
|
|
Top
|
|
|
|
#14273 - 2002-11-23 12:12 AM
Re: Find executables
|
CalderX
Fresh Scripter
Registered: 2002-04-24
Posts: 6
Loc: Boden north of Sweden
|
Hey!
Thanks for the quick answer but I´m a little new and my question is what to do with this sckript? What parameters and where in the script should I´l change it to get it to work? Lets say I´l want to search all exe-files in c:\winnt and put the result in a file, what is the code for that?
Calle [ 23. November 2002, 00:13: Message edited by: Calle ]
|
|
Top
|
|
|
|
#14275 - 2002-11-23 01:18 AM
Re: Find executables
|
CalderX
Fresh Scripter
Registered: 2002-04-24
Posts: 6
Loc: Boden north of Sweden
|
Thanks for the answer Lurenko!
I´l solved my problem with the script from member CO, I´l found it easier for me to understand.
Thanks again!
Calle
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 1257 anonymous users online.
|
|
|