Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - Script to retrieve file versions

Reply
 
Old 07-30-2008   #1 (permalink)
tke402


 
 

Script to retrieve file versions

hi,

I found this script on Scripting Guy. However I would like for the window to
have the results of three file versions. Here's what I have now. It shows in
three seperate windows one at a time:

strComputer = "Server1"

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set colFiles = objWMIService.ExecQuery _
("Select * from CIM_Datafile Where Name =
'c:\\windows\\system32\\setup.exe'")

For Each objFile in colFiles
Wscript.Echo objFile.Version
Next

strComputer = "Server2"

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set colFiles = objWMIService.ExecQuery _
("Select * from CIM_Datafile Where Name =
'c:\\windows\\system32\\setup.exe'")

For Each objFile in colFiles
Wscript.Echo objFile.Version
Next

strComputer = "Server3"

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set colFiles = objWMIService.ExecQuery _
("Select * from CIM_Datafile Where Name =
'c:\\windows\\system32\\setup.exe'")

For Each objFile in colFiles
Wscript.Echo objFile.Version
Next



My System SpecsSystem Spec
Old 07-30-2008   #2 (permalink)
mayayana


 
 

Re: Script to retrieve file versions

Did you know that you don't need WMI for that?
(Unless there's a problem using FSO across a network.
I've never tried that.)

-------------------
Set FSO = CreateObject("Scripting.FileSystemObject")
S = FSO.GetFileVersion("c:\windows\system32\setup.exe")
-------------------

If you want to show it all in one msgbox you can
use a variable to concatenate the values as you collect
them. Instead of using WScript.echo with each machine,
you can do something like this:

Dim sVer

Set colFiles = objWMIService.ExecQuery _
("Select * from CIM_Datafile Where Name =
'c:\\windows\\system32\\setup.exe'")

For Each objFile in colFiles
sVer = sVer & strComputer & " - " & objFile.Version & vbcrlf
Next

Do the same for each machine. Then at the end
you can show one window with:

MsgBox sVer

The window will show a list like:

Server1 - 1.055
Server2 - 1.055
Server3 - 1.061

Quote:

>
> I found this script on Scripting Guy. However I would like for the window
to
Quote:

> have the results of three file versions. Here's what I have now. It shows
in
Quote:

> three seperate windows one at a time:
>
> strComputer = "Server1"
>
> Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
>
> Set colFiles = objWMIService.ExecQuery _
> ("Select * from CIM_Datafile Where Name =
> 'c:\\windows\\system32\\setup.exe'")
>
> For Each objFile in colFiles
> Wscript.Echo objFile.Version
> Next
>
> strComputer = "Server2"
>
> Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
>
> Set colFiles = objWMIService.ExecQuery _
> ("Select * from CIM_Datafile Where Name =
> 'c:\\windows\\system32\\setup.exe'")
>
> For Each objFile in colFiles
> Wscript.Echo objFile.Version
> Next
>
> strComputer = "Server3"
>
> Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
>
> Set colFiles = objWMIService.ExecQuery _
> ("Select * from CIM_Datafile Where Name =
> 'c:\\windows\\system32\\setup.exe'")
>
> For Each objFile in colFiles
> Wscript.Echo objFile.Version
> Next
>
>

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
how to test a script for compatibility with different Windows Versions VB Script
Retrieve file from Recycle Bin issue General Discussion
problem passing args to script 'There is no script engine for file extenstion' VB Script
How to retrieve the latest file PowerShell
Retrieve the path of the file PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46