VB and VBA Users Source Code: Determine if file is a Windows or DOS executable
[
Home
|
Contents
|
Search
|
Reply
| Previous | Next ]
VB/VBA Source Code
Determine if file is a Windows or DOS executable
By:
Andrew Baker
Email (spam proof):
Email the originator of this post
Date:
Wednesday, March 21, 2001
Hits:
1101
Category:
Files/Directories/IO
Article:
To determine if an executable has been written for Windows or DOS you need to check byte offset 24 in the file. If it contains 40h, it's a Windows executable. Option Explicit 'Purpose : Determine if an executable has been written for Windows or DOS. 'Inputs : sFilePath The path and name of the executable. 'Outputs : Returns 1 if the file is a windows executable. ' Returns 0 if the file is a DOS executable. ' Returns -1 if the file doesn't exist. 'Author : Andrew Baker 'Date : 20/Mar/2001 21:40 'Notes : 'Assumptions : Function FileWindows(ByVal sFilePath As String) As Long Dim lhwndFile As Integer Dim sTest As String * 1 'Buffer If Len(sFilePath) > 0 And Len(Dir$(sFilePath)) > 0 Then lhwndFile = FreeFile Open sFilePath For Binary As #lhwndFile Get lhwndFile, 25, sTest Close #lhwndFile FileWindows = Abs(Asc(sTest) = &H40&) Else 'File doesn't exist FileWindows = -1 End If End Function 'Demonstration routine Sub Test() Select Case FileWindows("C:\FootballAid.exe") Case 1 MsgBox "Windows file" Case 0 MsgBox "DOS file" Case -1 MsgBox "file doesn't exist" End Select End Sub
Terms and Conditions
Support this site
Download a trial version of the Excel Workbook Rebuilder