How to Retrieve a File's “Product Version” in VBScript

前端 未结 5 869
你的背包
你的背包 2020-12-16 20:25

I have a VBScript that checks for the existence of a file in a directory on a remote machine. I am looking to retrieve the \"Product Version\" for said fil

5条回答
  •  自闭症患者
    2020-12-16 21:07

    ' 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
    

提交回复
热议问题