Page 1 of 1 1
Topic Options
#14259 - 2001-11-15 12:10 AM Find executables
Co Offline
MM club member
***

Registered: 2000-11-20
Posts: 1342
Loc: NL
Hey everyone,

I have the following problem:

I want to make a script which i can use to find *.exe files in all directories. I can use the dir /s /b *.exe > textfile.txt command to find all the files. After that i want more information about these files. Here begins my problem! How can i use the readline and getfileversion commando together so that the lines in textfile.txt can be used by the getfileversion commando?

I hope someone can help me. I think a script like this can be very usefull.

Co

_________________________
Co


Top
#14260 - 2001-11-14 03:49 PM Re: Find executables
Kdyer Offline
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

_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#14261 - 2001-11-14 08:55 PM Re: Find executables
Co Offline
MM club member
***

Registered: 2000-11-20
Posts: 1342
Loc: NL
Kdyer,

Thanks, at the first look your script is looking very nice. At this moment i'm very busy with the 70-217 exam(Transcenders, Selftest and MOC). In about 12 hours i will be back at the office. Then i'll test your script and give some comment. Í've said it before, I think a script like this can be usefull for a lot of people. I need a script like this to find an d remove executables like Get_Osama_bin_Laden.exe. For a lot of people a noble executable but not for the professional environment my colleagues and I control.. (Sorry!)

Co

_________________________
Co


Top
#14262 - 2001-11-15 05:41 AM Re: Find executables
MCA Offline
KiX Supporter
*****

Registered: 2000-04-28
Posts: 5152
Loc: Netherlands, EU
Dear,

Good luck with your exam.

For other ideas you can take a look at our script searchfiles.kix
which you can find on our site http://home.wanadoo.nl/scripting .
You can specify which directories or drives should be searched for
specified files.
The part :show_file_info can easily be changed to a delete file
operation. On the board you will find modified scripts of it.
When you need more help let it know us.
greetings.

btw: for speed is dir /B /S a good one.

_________________________
email scripting@wanadoo.nl homepage scripting@wanadoo.nl | Links | Summary of Site Site KiXforms FAQ kixtart.org library collection mirror MCA | FAQ & UDF help file UDF kixtart.org library collection mirror MCA | mirror USA | mirror europe UDF scriptlogic library collection UDFs | mirror MCA

Top
#14263 - 2001-11-15 11:29 AM Re: Find executables
Co Offline
MM club member
***

Registered: 2000-11-20
Posts: 1342
Loc: NL

Wow! Kent,
your script is very good. Just wat i needed.

Thanx

Co

_________________________
Co


Top
#14264 - 2001-11-15 03:35 PM Re: Find executables
Co Offline
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
#14265 - 2001-11-15 03:49 PM Re: Find executables
Bryce Offline
KiX Supporter
*****

Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
try this.

code:

$nul = open(1,$tempfile,2)
$file = readline(1)
do
? $file
$file = readline(1)
until @error <> 0


Top
#14266 - 2001-11-15 05:15 PM Re: Find executables
Co Offline
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 Offline
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.
_________________________
email scripting@wanadoo.nl homepage scripting@wanadoo.nl | Links | Summary of Site Site KiXforms FAQ kixtart.org library collection mirror MCA | FAQ & UDF help file UDF kixtart.org library collection mirror MCA | mirror USA | mirror europe UDF scriptlogic library collection UDFs | mirror MCA

Top
#14268 - 2001-11-16 03:11 AM Re: Find executables
Bryce Offline
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 Offline
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
#14270 - 2001-11-18 11:12 PM Re: Find executables
Co Offline
MM club member
***

Registered: 2000-11-20
Posts: 1342
Loc: NL
New problem: When the directory is too big and it's hierarchy goes too deep I get a Dr. Watson error for kix32.exe. I think the script becomes too busy.

C

_________________________
Co


Top
#14271 - 2002-11-22 10:29 PM Re: Find executables
CalderX Offline
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
#14272 - 2002-11-22 10:32 PM Re: Find executables
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
ok, I made an example script in dirScan() udf which does pretty much similar.
udf is at: http://www.kixtart.org/cgi-bin/ultimatebb.cgi?ubb=get_topic;f=12;t=000303

check the example, all you need to add is a little if checking for correct type [Smile]

enjoy.

{edit}
maybe I should enchange my UDF a little as bryce's dirplus resolves with less lines...

[ 22. November 2002, 22:36: Message edited by: Lonkero ]
_________________________
!

download KiXnet

Top
#14273 - 2002-11-23 12:12 AM Re: Find executables
CalderX Offline
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
#14274 - 2002-11-23 12:17 AM Re: Find executables
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
calle, I think you would go with either dirplus or dirscan.
both are UDF (user defined function see How to use UDFs)

for dirplus the usage is shown before and dirscan has it explained in it's header.
udf needs no changing.
the input you give to it is the part that you control.
_________________________
!

download KiXnet

Top
#14275 - 2002-11-23 01:18 AM Re: Find executables
CalderX Offline
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
#14276 - 2002-11-23 01:22 AM Re: Find executables
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
calle,
the only thing being that there is something you must do with that script.

the udf placed somewhere in your script and use it like bryce told (windir is the var for windows directory which varies by setup):

$dir = dirplus("%windir%",".exe",1)
for each $file in $dir
? $file
next

this little peace calls the dirplus which is wherever you want in the script file and returns all the exe's in your windows directory.
can it be hard?
_________________________
!

download KiXnet

Top
#14277 - 2002-11-23 04:12 AM Re: Find executables
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Calle: You might want ot read the KiXtart Manual and the FAQ Fourm as there are a lot of good tips on how to write a KiXtart script.

And experiment a little bit with a simple script.
_________________________
There are two types of vessels, submarines and targets.

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 1442 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.074 seconds in which 0.024 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org