Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Finding original exe name 1

Status
Not open for further replies.

windoz255

Technical User
Apr 8, 2003
17
GB
Hi,

Can anyone assist me in how I can find the original name for a file.

For example;

calc.exe

If i change this to say ca.exe, and I check the original file name(right click, properties and check version (XP)), it says calc.exe (original file name). I can still run calculator but the computer acknowledges this as ca.exe in the process window. Anyone know how to retrieve the original file name from the exe.

Any examples, URL's or advice would be good.

Thanks.
 
App.ExeName

Chip H.


If you want to get the best response to a question, please check out FAQ222-2244 first
 
You can use the file version information APIs (version.dll) to query the original filename from the exe file.
___
[tt]
Option Explicit
Private Declare Function VerQueryValue Lib "version" Alias "VerQueryValueA" (pBlock As Any, ByVal lpSubBlock As String, lplpBuffer As Long, puLen As Long) As Long
Private Declare Function GetFileVersionInfoSize Lib "version" Alias "GetFileVersionInfoSizeA" (ByVal lptstrFilename As String, lpdwHandle As Long) As Long
Private Declare Function GetFileVersionInfo Lib "version" Alias "GetFileVersionInfoA" (ByVal lptstrFilename As String, ByVal dwHandle As Long, ByVal dwLen As Long, lpData As Any) As Long
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)

Function GetOriginalFileName(FileName As String) As String
Dim VerInfoSize As Long, lpdwHandle As Long, Buffer() As Byte
Dim strLangCharSet As String, lpData As Long, cbData As Long

'Query the size of the version info data
VerInfoSize = GetFileVersionInfoSize(FileName, lpdwHandle)
If VerInfoSize = 0 Then Exit Function

'Create the version info buffer and query the data
ReDim Buffer(0 To VerInfoSize - 1)
If GetFileVersionInfo(FileName, 0, VerInfoSize, Buffer(0)) = 0 Then Exit Function

'Query the language/character set identifier
If VerQueryValue(Buffer(0), "\VarFileInfo\Translation", lpData, cbData) = 0 Then Exit Function
CopyMemory lpData, ByVal lpData, 4
strLangCharSet = Hex$(lpData) 'convert to hex
strLangCharSet = Right$("00000000" & strLangCharSet, 8) 'pad leading zeroes
strLangCharSet = Right$(strLangCharSet, 4) & Left$(strLangCharSet, 4) 'swap the upper and lower words

'Query the original file name
Dim S As String
If VerQueryValue(Buffer(0), "\StringFileInfo\" & strLangCharSet & "\OriginalFilename", lpData, cbData) = 0 Then Exit Function
S = Space$(cbData)
CopyMemory ByVal S, ByVal lpData, cbData
GetOriginalFileName = Split(S, vbNullChar)(0)
End Function

Private Sub Form_Load()
MsgBox GetOriginalFileName("calc.exe")
End Sub[/tt]
___

You can pass the path of any executable file to retrieve its orginal file name specified at the time of compilition.
 
The code given by Hypetia really works well. I have searched various websites for this information but to no avail.

Thanks again for replying everyone.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top