Version 0 of Reading version information from Win32 executables

Updated 2003-05-22 16:00:56

AF 10-05-03

 proc readVersionInfo {file} {
    set fh [open $file r]
    fconfigure $fh -encoding unicode
    set data [read $fh]
    set startchar [string first "StringFileInfo\000" $data]
    if {$startchar < 0} {
        return {{} {} {} {} {} {} {} {} {}}
    }
    foreach x {
       CompanyName OriginalFilename ProductName ProductVersion
       FileDescription FileVersion InternalName LegalCopyright LegalTrademarks} {
        set s [string first "$x\000" $data $startchar]
        set e [string first "\000" $data [expr $s + [string length $x] + 2]]
        if {$s < 0 || $e < 0} {
            lappend prop {}
            continue
        }
        lappend prop [string range $data [expr $s + [string length $x] + 1] $e]
    }
    close $fh
    return $prop
 }

 set name {"Company Name" "Original Filename" "Product Name" 
           "Product Version" "File Description" "File Version" "Internal 
           Name" "Copyright" "Trademarks"}

 foreach n $name prop [readVersionInfo tclkit.exe] {
    puts "$n: $prop"
 }