Jump to content

Help with call to GetFileVersionInfo


Recommended Posts

Does anyone have experience here with retrieving "Company Name" and "Description" from a file using GetFileVersionInfo? I am having a hard time even finding a simple explanation of how to do it in visual basic or c++, much less autoit. Can anyone point me in the right direction how to get those two types of information out of a dll or exe file?

Who else would I be?
Link to comment
Share on other sites

Does anyone have experience here with retrieving "Company Name" and "Description" from a file using GetFileVersionInfo? I am having a hard time even finding a simple explanation of how to do it in visual basic or c++, much less autoit. Can anyone point me in the right direction how to get those two types of information out of a dll or exe file?

<{POST_SNAPBACK}>

You can use Resource Hacker to get the information, but that is not as interesting as writing an AutoIt script to do it.

If you are feeling really adventurous, you can execute Resource Hacker, hide the window, and use ControlSend() to pull out the relevant information from the text in the right-paned window. The information you are requesting will be under "Version Info", "1", "1033" in case you are wondering.

Good Luck.

Link to comment
Share on other sites

I am close, but I need some help on the last call:

$flnm = @SystemDir & "\shell32.dll"
$str = DllStructCreate("char[" & StringLen($flnm) + 1 & "]")
DllStructSetData($str, 1, $flnm)
$dword = DllStructCreate("dword")
$ret = DllCall("version.dll", "int", "GetFileVersionInfoSize", "ptr", DllStructGetPtr($str), "ptr", DllStructGetPtr($dword))
MsgBox(0,"",$ret[0])
$verinfo = DllStructCreate("char[" & $ret[0] & "]")
$ret2 = DllCall("version.dll", "int", "GetFileVersionInfo", "ptr", DllStructGetPtr($str), "int", 0, "int", $ret[0], "ptr", DllStructGetPtr($verinfo))
MsgBox(0,"",$ret2[0])

;$val = "\StringFileInfo\040904E4\CompanyName"
$val = "\StringFileInfo\040904E4\FileDescription"
$str2 = DllStructCreate("char[" & StringLen($val) & "]")
DllStructSetData($str2, 1, $val)
$len = DllStructCreate("int")

$ret3 = DllCall("version.dll", "int", "VerQueryValue", "ptr", DllStructGetPtr($verinfo), "ptr", DllStructGetPtr($str2), "ptr", "", "ptr", DllStructGetPtr($len))
Local $lastError = DllCall("kernel32.dll", "int", "GetLastError")
MsgBox(0,"",$lastError[0])

The error message is ERROR_RESOURCE_TYPE_NOT_FOUND

What did I miss? the zero-padding? I tried adding 0's to the end of the string variable, but that didn't make any difference.

Who else would I be?
Link to comment
Share on other sites

$flnm = @SystemDir & "\shell32.dll"
   $str = DllStructCreate("char[" & StringLen($flnm) + 1 & "]")
      DllStructSetData($str, 1, $flnm)
         $dword = DllStructCreate("dword")
$ret = DllCall("version.dll", "int", "GetFileVersionInfoSize", "ptr", DllStructGetPtr($str), "ptr", DllStructGetPtr($dword))
MsgBox(0,"",$ret[0])

$verinfo = DllStructCreate("char[" & $ret[0] & "]")
$ret2 = DllCall("version.dll", "int", "GetFileVersionInfo", "ptr", DllStructGetPtr($str), "int", 0, "int", $ret[0], "ptr", DllStructGetPtr($verinfo))
MsgBox(0,"",$ret2[0])

;$val = "\StringFileInfo\040904E4\CompanyName"
$val = "\StringFileInfo\040904E4\FileDescription"
$str2 = DllStructCreate("char[" & StringLen($val) & "]")
DllStructSetData($str2, 1, $val)
$len = DllStructCreate("int")

;$ret3 = DllCall("version.dll", "int", "VerQueryValue", "ptr", DllStructGetPtr($verinfo), "ptr", DllStructGetPtr($str2), "ptr", "", "ptr", DllStructGetPtr($len))
$ret3 = DllCall("version.dll", "int", "VerQueryValue", "ptr", DllStructGetPtr($verinfo), "str", $val, "ptr", "", "ptr", DllStructGetPtr($len))
MsgBox(0,"", 'returned value from VerQueryValue: ' & $ret3[1])
Local $lastError = DllCall("kernel32.dll", "int", "GetLastError")
;MsgBox(0,"", '$lastError[0]: ' & $lastError[0])

I believe it works now, but I don't know what value you expect from VerQueryValue.

Link to comment
Share on other sites

OK. From this point I am once again at a loss to get the information I need from this structure, especially considering I am not the best person to "translate" from visual basic to autoit.

Here is what I want to do:

http://www.experts-exchange.com/Programmin...Q_20306198.html

Here is what I have:

$flnm = @SystemDir & "\shell32.dll"
$str = DllStructCreate("char[" & StringLen($flnm) + 1 & "]")
DllStructSetData($str, 1, $flnm)
$dword = DllStructCreate("dword")
$ret = DllCall("version.dll", "int", "GetFileVersionInfoSize", "ptr", DllStructGetPtr($str), "ptr", DllStructGetPtr($dword))

$verinfo = DllStructCreate("char[" & $ret[0] & "]")
$ret2 = DllCall("version.dll", "int", "GetFileVersionInfo", "ptr", DllStructGetPtr($str), "int", 0, "int", $ret[0], "ptr", DllStructGetPtr($verinfo))

;$val = "\StringFileInfo\040904E4\CompanyName"
$val = "\StringFileInfo\040904E4\FileDescription"
$str2 = DllStructCreate("char[" & StringLen($val) & "]")
DllStructSetData($str2, 1, $val)
$len = DllStructCreate("int")

$buf = DllStructCreate("char[256]")
$buf2 = DllStructCreate("char[256]")
DllStructSetData($buf, 1, DllStructGetPtr($buf2))

$ret3 = DllCall("version.dll", "int", "VerQueryValue", "ptr", DllStructGetPtr($verinfo), "str", $val, "ptr", DllStructGetPtr($buf), "ptr", DllStructGetPtr($len))

Can someone tell me how to get a readable string out of the return from the last dllcall? I see some places mentioning MoveMemory, some list lstrcpy, some do both, but I am at a loss to see how it can be done in AutoIt. Is anyone up to the challenge?

Who else would I be?
Link to comment
Share on other sites

this-is-me, I haven't used these API calls so I am not familiar with them. I suspect they are not very straight-forward, however, because nothing in this "area" is straight-forward. Never-the-less, there should be a direct correlation between the description of the function on MSDN and the ways to create the structure. However, if you continue to want to use DllCall() and structures, my advice to you is to learn C. Not the whole language, of course, but at least get yourself a basic grasp of types. Without a basic knowledge of what a pointer is and what each inherent type is and how Windows maps these types to "common" names, you're going to get nowhere without the help of somebody who does know these things.

Every Windows data-type is either a structure or can be traced back to a C built-in type. It may require some research, but it shouldn't be too hard to figure out what the built-in types are for some of the "funny" names. Use a scratch pad if necessary to make the correlation more readily apparent. There is a way to trace everything back to the built-in types which AutoIt supports, or the next closest thing. The size of a type is more important than it's "type". Getting even the most basic understanding of this is sufficient for being proficient with DllStruct* and DllCall().

This is one of those "give a man a match and he'll be warm for the rest of the night; light a man on fire and he'll be warm for the rest of his life" speeches.

Link to comment
Share on other sites

Well, Valik, thanks for "pointing" me in the right direction. I appreciate the time you put into replying to these problems I am facing. I will try to look into C and see what arises.

Thanks again.

Who else would I be?
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...