Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VB Script to determine a file version

Status
Not open for further replies.

blackrabbit

IS-IT--Management
Aug 22, 2002
204
0
0
US
Here is the situation... We have a small app that needs to be updated on several hundred servers. The upgrade itself is easy, just copy two files to the servers to replace the older ones.

We want to create a script to determine the current version of the files on the server and if that version is below a certain value then it copies over the new updated files.

Here is our problem. If you go to the properties of the exe files we need to replace and check the file there is no version listed for the exe files. It's a third party app so we can't get around it. If you run the exe with a certain switch from the command prompt it will output to the screen the current version of the exe so I thought we could use that. I just don't know how to do it.

I want the script to run the exe with the switch and capture that output to a variable, from there I can easily take that info and determine if new files are needed. I just can't figure out how to have the vb script run the exe with the switch and capture the output to a variable. Any help would be appreciated. Thanks.
 

First off, this is the forum for VB .NET, not VB Script. That said, you can still do this with VB .NET. You just need to run the exe from the command line with the desired switches, then capture the output:

Dim p As New System.Diagnostics.Process
Dim sw As System.IO.StreamWriter
Dim sr As System.IO.StreamReader
Dim ThisLine As String

p.StartInfo.FileName = "cmd"
p.StartInfo.UseShellExecute = False
p.StartInfo.RedirectStandardInput = True
p.StartInfo.RedirectStandardOutput = True
p.StartInfo.CreateNoWindow = True

p.Start()

sw = p.StandardInput
sr = p.StandardOutput

sw.WriteLine("YourEXE.exe /switches") 'use your exe and switches just like in a command prompt

Do Until sr.EndOfStream = True

ThisLine = sr.ReadLine

'do stuff with ThisLine to determine
'if the file version is there

'Do stuff with the file version
'to do the copy or not

Loop

p.Dispose()
sw.Close()
sw.Dispose()
sr.Close()
sr.Dispose()


I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!
 
We thought about the date but sometimes the guys who build servers put older versions on instead of the newer ones. File size might work too but even that may not be fool proof as a newer version might get streamlined and have a smaller size than an older one at some point. They are all worth a try though to see if I can get it to work.
 
I was thinking that in the code for the upgrade would be a hardcoded 'database' of dates and sizes that would translate into a version number. e.g if the file is dated 2010-10-02 and has a size of 11,239 (or maybe a small size range ) then is it version 1.05 etc.

But it looks like jebenson's answer is better then this suggestion anyhow.





Lion Crest Software Services
Anthony L. Testi
President
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top