C
CSharp
C++
Java
Visual Basic
HTML - CSS
Android
Asp
Asp.Net
Php
Python
JavaScript
SQL
XML
Assembly
ActiveX
API
Code Snippets
Database
Files Directories Drives
Forms
Graphics Games
Multimedia
Strings
Windows and Controls
More...
Visual Basic > Files Directories Drives sample source codes
Visual Basic Code > Determine if file is a Windows or DOS executable
Determine if file is a Windows or DOS executable 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. 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
Privacy Policy
|
Contact
|
Advertising
|
Link to Us
|
Directory