2010-06-04 19 views
7

Tengo un VBScript que comprueba la existencia de un archivo en un directorio en una máquina remota. Estoy buscando recuperar el "Producto versión" para dicho archivo (NO "Versión de archivo"), pero parece que no puedo encontrar la manera de hacerlo en VBScript.Cómo recuperar la "Versión del producto" de un archivo en VBScript

Actualmente estoy usando Scripting.FileSystemObject para verificar la existencia del archivo.

Gracias.

+0

Aquí es una pregunta muy similar acerca de JScript - [Detección de la versión y la compañía Nombre de un exe utilizando JScript] (http: // stackoverflow .com/questions/1674134 /) – Helen

Respuesta

0

No creo que pueda hacerlo en vbScript. Yo podría estar equivocado en eso.

Aquí hay un enlace a un script de powershell que hace lo que está pidiendo.

link text

Esto es lo que la salida para mi dir ventanas se parece.

Scripts PS:> ls c: \ windows * .exe | . \ get-fileversion.ps1

ProductVersion FileVersion FileName -------------- ----------- -------- 2.7 .3.0 2.7.3.0 C: \ windows \ agrsmdel.exe

2

Puede usar el Shell.Namespace para obtener el extended properties en un archivo, uno de los cuales es la versión del producto. La función GetDetailsOf debería funcionar. Puede probar con el siguiente código para tener una idea:

Dim fillAttributes(300) 

Set shell = CreateObject("Shell.Application") 
Set folder = shell.Namespace("C:\Windows") 

Set file = folder.ParseName("notepad.exe") 

For i = 0 to 299 
    Wscript.Echo i & vbtab & fillAttributes(i) _ 
     & ": " & folder.GetDetailsOf(file, i) 
Next 

Una cosa a tener en cuenta:

Las propiedades extendidas de un archivo difiere entre las versiones de Windows. Por lo tanto, los números de índice de la versión del producto cambian según la versión de Windows que esté utilizando. Puede usar el código anterior para determinar cuáles son. De mis pruebas, creo que son los siguientes:

  • Windows XP - 39
  • Windows Vista - 252
  • Windows 7 - 268
  • Windows 2008 R2 SP1 - 271
  • de Windows 2012 R2 - 285

También puede encontrar las siguientes post útil.

8

Uso una función que está ligeramente modificada con respecto al ejemplo anterior. La función toma el nombre de ruta y el archivo y devuelve la "Versión del producto"

Function GetProductVersion (sFilePath, sProgram) 
Dim objShell, objFolder, objFolderItem, i 
If FSO.FileExists(sFilePath & "\" & sProgram) Then 
    Set objShell = CreateObject("Shell.Application") 
    Set objFolder = objShell.Namespace(sFilePath) 
    Set objFolderItem = objFolder.ParseName(sProgram) 
    Dim arrHeaders(300) 
    For i = 0 To 300 
     arrHeaders(i) = objFolder.GetDetailsOf(objFolder.Items, i) 
     'WScript.Echo i &"- " & arrHeaders(i) & ": " & objFolder.GetDetailsOf(objFolderItem, i) 
     If lcase(arrHeaders(i))= "product version" Then 
      GetProductVersion= objFolder.GetDetailsOf(objFolderItem, i) 
      Exit For 
     End If 
    Next 
End If 
End Function 

he encontrado que la posición de los atributos se cambia de vez en cuando (no sé por qué) en XP y Vista así que busque el " atributo "versión de producto" y salir del bucle una vez que se encuentre.La línea comentada mostrará todos los atributos y un valor si está disponible

0
Wscript.Echo CreateObject("Scripting.FileSystemObject").GetFileVersion("C:\Windows\notepad.exe") 
+0

El OP dijo * Versión del producto *, no * Versión del archivo *. No són la misma cosa. – Helen

+0

No es una respuesta correcta. – CCoder

0
' must explicitly declare all variables 
Option Explicit 
' declare global variables 
Dim aFileFullPath, aDetail 
' set global variables 
aFileFullPath = "C:\Windows\Notepad.exe" 
aDetail = "Product Version" 
' display a message with file location and file detail 
WScript.Echo ("File location: " & vbTab & aFileFullPath & vbNewLine & _ 
aDetail & ": " & vbTab & fGetFileDetail(aFileFullPath, aDetail)) 
' make global variable happy. set them free 
Set aFileFullPath = Nothing 
Set aDetail = Nothing 
' get file detail function. created by Stefan Arhip on 20111026 1000 
Function fGetFileDetail(aFileFullPath, aDetail) 
' declare local variables 
Dim pvShell, pvFileSystemObject, pvFolderName, pvFileName, pvFolder, pvFile, i 
' set object to work with files 
Set pvFileSystemObject = CreateObject("Scripting.FileSystemObject") 
' check if aFileFullPath provided exists 
If pvFileSystemObject.FileExists(aFileFullPath) Then 
' extract only folder & file from aFileFullPath 
pvFolderName = pvFileSystemObject.GetFile(aFileFullPath).ParentFolder 
pvFileName = pvFileSystemObject.GetFile(aFileFullPath).Name 
' set object to work with file details 
Set pvShell = CreateObject("Shell.Application") 
Set pvFolder = pvShell.Namespace(pvFolderName) 
Set pvFile = pvFolder.ParseName(pvFileName) 
' in case detail is not detected... 
fGetFileDetail = "Detail not detected" 
' parse 400 details for given file 
For i = 0 To 399 
' if desired detail name is found, set function result to detail value 
If uCase(pvFolder.GetDetailsOf(pvFolder.Items, i)) = uCase(aDetail) Then 
fGetFileDetail = pvFolder.GetDetailsOf(pvFile, i) 
End If 
Next 
' if aFileFullPath provided do not exists 
Else 
fGetFileDetail = "File not found" 
End If 
' make local variable happy. set them free 
Set pvShell = Nothing 
Set pvFileSystemObject = Nothing 
Set pvFolderName = Nothing 
Set pvFileName = Nothing 
Set pvFolder = Nothing 
Set pvFile = Nothing 
Set i = Nothing 
End Function 
+1

Bienvenido a SO. Por favor explique el código en sus respuestas. – Tim

Cuestiones relacionadas