• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 724
  • Last Modified:

Get the File Version from txt

Hi,

I have  file list (filelist.txt). I need to make a Batch file or Vbscript to search the PC for the files that are in the filelist.txt to get the version for these files and then output to a resultfileversion.txt in the following format:

---------------------------------------------------------------------
Name:                                          Value		
---------------------------------------------------------------------`

Dup.dll,2.06.2.30
Julop.dll,3.1.15.20
Rthgl.dll,5.0.0..2
……………
…………
Vder.dll,2.0.3.6

Open in new window


Thanks for your help and quick prompt.
0
NetRock6
Asked:
NetRock6
  • 14
  • 14
  • 3
2 Solutions
 
Bill PrewCommented:
In FILELIST.TXT, will you have the full path to the file?  If not, how would you like to locate it, via the Windows PATH, or always look in a particular Windows folder, etc?

Getting the actual file version information is very easy in VBS, and so is reading the list file and writing a report.  The biggest challenge is locating the file you want in the folder it resides in.

Set objFSO = CreateObject("Scripting.FileSystemObject")
Wscript.Echo objFSO.GetFileVersion("c:\windows\system32\scrrun.dll")

Open in new window

~bp
0
 
Steve KnightIT ConsultancyCommented:
Well Bill got in before me there, was thinking roughly the same.  We could read the registry to see where that dll is registered or the like, or brute force check the whole drive.  Quite possible there may be more than one for each to deal with too of course.  What about those inside, for instance, ntuninstall directories etc?

Steve
0
 
NetRock6Author Commented:
Thanks Bill for the quick reply.
So, there is no utility that can search the PC for the listed files to get the version....
I am looking for "filever.exe" for windows 7, to see if i need to assign the path for the files using this utility.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
Bill PrewCommented:
Here's a quick approach that would get the job done if the list.txt file had the full path to the file.  If not, we just need to add some logic to locate the file based on the approach desired.  I don't know if the files you want to get the version of are all Windows files, or all in the same folder, or some installed programs files, etc.

The input and output files are taken from the command line, so run it like this:

cscript EE27856922.vbs files.txt report.txt

' Define needed constants
Const ForReading = 1
Const ForWriting = 2
Const TriStateUseDefault = -2

' Get input and output file names from command line parms
If (WScript.Arguments.Count > 0) Then
  sInfile = WScript.Arguments(0)
Else
  WScript.Echo "No input filename specified."
  WScript.Quit
End If
If (WScript.Arguments.Count > 1) Then
  sOutfile = WScript.Arguments(1)
Else
  WScript.Echo "No output filename specified."
  WScript.Quit
End If

' Create file system object
Set oFSO = CreateObject("Scripting.FileSystemObject")

' Open input and output files
Set oInfile = oFSO.OpenTextFile(sInfile, ForReading, False, TriStateUseDefault)
Set oOutfile = oFSO.OpenTextFile(sOutfile, ForWriting, True)

' Read input file line by line
Do While Not oInfile.AtEndOfStream
   sLine = oInfile.ReadLine
   sVersion = oFSO.GetFileVersion(sLine)
   oOutfile.WriteLine sLine & "," & sVersion
Loop

' Cleanup and end
oInfile.Close
oOutfile.Close
Set oInfile = Nothing
Set oOutfile = Nothing
Set oFSO = Nothing

Open in new window

~bp
0
 
Bill PrewCommented:
filever was a windows toolkit addon as I recall. not shipped with the O/S, but downloadable.

Another tool you can download and use (if that is allowed) is sigcheck, at:

http://technet.microsoft.com/en-us/sysinternals/bb897441.aspx

You might want to use these along with WHERE on Windows 7 to solve this in a BAT script.

~bp
0
 
NetRock6Author Commented:
Thanks Bill for the Script.
Yes! i could get sigcheck but what you mean by:

" use these along with WHERE on Windows 7 to solve this in a BAT script"

Thanks
0
 
Bill PrewCommented:
Short on time, but here's the basic idea for a BAT file.  Not sure how savy you are there, but happy to explain if this doesn't make sense.  Basically we get each line from the text file, use WHERE against the file name to get the full path, and then use SIGCHECK against the full path to get the version info.

@echo off
set InputFile=in.txt
set ReportFile=out.txt
for /F "usebackq tokens=*" %%A in ("%InputFile%") do (
  for /F "tokens=1" %%B in ('where "%%~A"') do (
    for /F "tokens=1" %%C in ('sigcheck.exe -n -q "%%~B"') do (
      echo %%~A,%%~C>>"%ReportFile%"
    )
  )
)

Open in new window

~bp
0
 
NetRock6Author Commented:
I tried sigcheck without -n switch it works great, but still needs the full path to the file.
see below:

@ECHO OFF

FOR /F "tokens=1-3" %%i IN ('sigcheck C:\windows\system32\Dup.dll') DO ( IF "%%i %%j"=="File version:" SET filever=%%k )

ECHO %filever%

Open in new window

0
 
NetRock6Author Commented:
Just saw your post @  10:30:28 i will try!
Big Thanks
0
 
Bill PrewCommented:
Try my BAT above...

~bp
0
 
Bill PrewCommented:
I'll be away for a few hours now, hope that gave you some starting points.

~bp
0
 
NetRock6Author Commented:
the Batch file works great thanks a lot.
But the "where" command is not able to find file in:
\windows\system32\drivers

any idea how to fix this issue
0
 
Steve KnightIT ConsultancyCommented:
It should be able to.  By default it will look only in the path and current dir.  If you want it to look everywherre you need to do something like:

where /r c:\ "whatever.dll"

Steve
0
 
NetRock6Author Commented:
Thanks Steve. It works fine.

I am trying to avoid having two identical entries in "out.txt" using Bill's batch file above.
because dll files are also stored in repository folder. Is there a way to avoid having double...

Thanks
0
 
NetRock6Author Commented:
Below does the trick .....
for /f "tokens=* delims= " %%a in (%1) do (
find "%%a" < outfile > nul
if errorlevel 1 echo %%a >> outfile
)

Open in new window

0
 
Bill PrewCommented:
Do you get the duplicates when WHERE finds it in two places?  And if so do you care which one it reports on?

~bp
0
 
NetRock6Author Commented:
Not really. all are the same files any way,  just doubled out!!
0
 
Bill PrewCommented:
And I think you could shrink your dedupe routine down a bit to:

for /f "tokens=* delims= " %%a in (%1) do (
  find "%%a" < outfile > nul || echo.%%a >> outfile
)

Open in new window

~bp
0
 
NetRock6Author Commented:
Thank you Bill for your amazing Fast Help,
as usual.!
0
 
Bill PrewCommented:
And of course, you could combine it all into one like this:

@echo off
setlocal EnableDelayedExpansion

REM Define input and output files
set InputFile=in.txt
set ReportFile=out.txt

REM Delete the output file if it already exists
if exist "%ReportFile%" del "%ReportFile%"

REM Read each line of the input file list
for /F "usebackq tokens=*" %%A in ("%InputFile%") do (

  REM Use the WHERE command to locate the full path(s) to this file
  for /F "tokens=1" %%B in ('where "%%~A"') do (

    REM Use SIGCHECK to get the version number of this file
    for /F "tokens=1" %%C in ('sigcheck.exe -n -q "%%~B"') do (

      REM Save in a variable
      set Ver=%%~A,%%~C

      REM Write to output file, making sure we don't allow duplicates of the same file
      if exist "%ReportFile%" (
        find "!Ver!" <"%ReportFile%" >NUL 2>&1 || echo.!Ver! >>"%ReportFile%"
      ) else (
        echo.!Ver! >>"%ReportFile%"
      )

    )

  )

)

Open in new window

~bp
0
 
NetRock6Author Commented:
Amazing and Fast response ....
Thanks
0
 
Bill PrewCommented:
Glad that was useful, that was a fun one, and thanks for the feedback!

~bp
0
 
Steve KnightIT ConsultancyCommented:
Thanks for the assist, was only chipping in while Bill was away.

Amazed at what you come up with sometimes Bill !



Steve
0
 
Bill PrewCommented:
Thanks Steve, and as always, it's a pleasure collaborating.

~bp
0
 
NetRock6Author Commented:
Thank you so much Bill for follow up and Completing the last phase!
Great job.

I was wondering, what is the disadvantages of enabling "EnableDelayedExpansion"
permentaly through registery.

Once again, Thank you!
0
 
Bill PrewCommented:
I think the only real drawback is that you can't use the ! character as a normal character in your batch files, it will be interpreted as indicating a variable.  But that typically isn't a problem.

~bp
0
 
NetRock6Author Commented:
Hi Bill,
I got to a big problem where windows 7 would keep a copy of the previous version of the dll files in FileRepository folder, is there way to modify the batch to get the highest version number .
Thanks for your quick prompt.
0
 
Bill PrewCommented:
Are you using my code as is from http:#a38377921, or have you modified it?  If modified, can you post what you are using, and also the output showing the case where a file appears more than once with different versions?

Are you using the WHERE command to locate files, or are you scanning the entire C:\ drive as was mentioned earlier?  Any reason not to just exclude the entire FileRepository folder?

~bp
0
 
NetRock6Author Commented:
Thanks for the reply.  I have added more lines to the initial code but I guess I just go with omitting the folder. Let you know how it goes

Thanks for your kind help
0
 
NetRock6Author Commented:
Hi Bill,

Having a really.... hard day yesterday, what i found out is that (and this is "Funny & Sad" story):
to test my code someone created a dummy dll files where only file versions were changed, guess what, this part was not done properly.... that leads to lots unnecessary aggravations...
but the good thing out of this is How you jump on to help...
That alone gave me lots of boost of confidence ....!
Simply Amazing ... Thank you! Thank you!
0
 
Bill PrewCommented:
Thanks for the feedback, glad I was able to help out, you were great to work with.

~bp
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

  • 14
  • 14
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now