Zjištění, zda je EXE pro DOS nebo Windows

Postup:
Option Explicit

' Vstup : sFilePath - cesta a jméno EXE souboru
' Výstup : Vrací 1 pokud se jedná o EXE pro Windows.
' Vrací 0 pokud je to EXE pro DOS.
' Vrací -1 pokud soubor neexistuje.

Function FileWindows(ByVal sFilePath As String) As Long

   Dim lhwndFile As Integer
   Dim sTest As String * 1 

   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
      FileWindows = -1
   End If

End Function

'Testovací procedurka
Sub Test()

   Select Case FileWindows("C:\bozena.exe")
      Case 1
         MsgBox "Soubor pro Windows"
      Case 0
         MsgBox "Soubor pro DOS"
      Case -1
         MsgBox "Hm, soubor neexistuje"
   End Select

End Sub

Zpět

Autor: The Bozena